Top Description Fields Constructors Methods
org.hsqldb.util.preprocessor

public Class Document

extends Object
Class Inheritance
Annotations
@SuppressWarnings:ClassWithoutLogger
Imports
java.io.BufferedReader, .BufferedWriter, .File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .InputStreamReader, .OutputStream, .OutputStreamWriter, .Reader, .Writer, java.nio.charset.Charset, java.util.ArrayList, .List

Simple line-oriented text document ADT.
Author
Campbell Burnet (campbell-burnet@users dot sourceforge.net)
Since
1.8.1
Version
2.7.0

Field Summary

Modifier and TypeField and Description
private final List<String>

Constructor Summary

AccessConstructor and Description
public
Document()

constructs a new, empty instance.

public
Document(final Document
to copy; may be null, which is treated like an empty instance.
source
)

Constructs a new instance that is effectively a copy of source.

Method Summary

Modifier and TypeMethod and Description
public Document

Returns:

this instance.
addSouceLine
(final String
to add; must not be null.
line
)

to this instance.

public Document

Returns:

this instance
appendDocument
(final Document
to append; may be null, which is treated like an empty instance.
source
)

to this instance.

public Document

Returns:

this instance.
clear
()

this instance, making it empty.

public boolean

Returns:

true if the condition holds, else false.
contains
(final CharSequence
to test.
sequence
)

if at least one line in this instance contains the given sequence.

public boolean

Returns:

true if the content of the given document is equal to the content of this instance, as per List#equals(Object).
contentEquals
(final Document
to test; may be null, which is treated as empty.
document
)

if the given document has effectively the same content as this instance.

public Document

Returns:

this instance.
deleteSourceLine
(final int
at which to remove a line.
index
)

from this instance at the given index.

public String

Returns:

the line at the given index.
getSourceLine
(final int
at which to retrieve the line.
index
)

at the given index.

public Document

Returns:

this instance
insertSourceLine
(final int
at which the specified line is to be inserted
index
,
final String
to be inserted
line
)

at the specified index.

public boolean

Returns:

true if size() == 0, else false.
isEmpty
()

if this instance contains no lines.

public static boolean

Returns:

true if supported, else false.
isSupportedCharset
(final String
to test; null returns false.
charsetName
)

for the given character set name.

public Document

Returns:

this object.
load
(final InputStream
from which to load; must not be null.
inputStream
,
final String
null for the system default.
encoding
)

this instance from the given input stream using the given character encoding.

public Document

Returns:

this object.
load
(final Reader
from which to load; must not be null.
reader
)

this instance from the given reader.

public Document

Returns:

this object.
load
(final File
from which to load; null is treated the empty path.
file
,
final String
null for the system default.
encoding
)

this instance from the given file using the given character encoding.

public Document

Returns:

this object.
load
(final String
from which to load; null is treated the empty path.
path
,
final String
null for the system default.
encoding
)

this instance from the given abstract file path using the given character encoding.

protected Document

Returns:

this instance.
load
(final Object
required; by default, must be an instance of an InputStream, Reader, File, or String denoting an abstract file path.
source
,
final String
optional; ignored if source is a Writer. null is taken to be Charset#defaultCharset().
encoding
)

this instance from the given source.

public Document

Returns:

this instance.
replaceWith
(final Document
content used to replace the existing content of this instance; may be null, which is treated as empty.
source
)

as if by invoking this.clear().appendDocument(source).

public Document

Returns:

this object.
save
(final OutputStream
to which to save; must not be null.
outputStream
,
final String
null for the system default.
encoding
)

to the given output stream using the given character encoding.

public Document

Returns:

this object.
save
(final File
to which to save; null is treated as having an empty path
file
,
final String
null for the system default.
encoding
)

to the given file using the given character encoding.

public Document

Returns:

this object.
save
(final String
to which to save; null is treated as the empty path;
path
,
final String
null for the system default.
encoding
)

to the given abstract file path using the given character encoding.

public Document

Returns:

this object.
save
(final Writer
to which to save; must not be null.
writer
)

to the given writer.

protected Document

Returns:

this instance.
save
(final Object
required; by default, must be an instance of an OutputStream, Writer, File, or String denoting an abstract file path.
target
,
final String
optional; does not apply to Writer. null is taken to be Charset#defaultCharset().
encoding
)

this instance to the given target.

public Document

Returns:

this instance.
setSourceLine
(final int
index of the line to replace
index
,
final String
to be stored at the specified index
line
)

at the specified index in this instance.

public int

Returns:

the number of lines in this instance.
size
()

of this instance, as the number of lines.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

linesback to summary
private final List<String> lines

Constructor Detail

Documentback to summary
public Document()

constructs a new, empty instance.

Documentback to summary
public Document(final Document source)

Constructs a new instance that is effectively a copy of source.

Parameters
source:Document

to copy; may be null, which is treated like an empty instance.

Method Detail

addSouceLineback to summary
public Document addSouceLine(final String line)

to this instance.

Parameters
line:String

to add; must not be null.

Returns:Document

this instance.

Exceptions
IllegalArgumentException:
if line is null.
appendDocumentback to summary
public Document appendDocument(final Document source)

to this instance.

Parameters
source:Document

to append; may be null, which is treated like an empty instance.

Returns:Document

this instance

Annotations
@SuppressWarnings:AccessingNonPublicFieldOfAnotherObject
clearback to summary
public Document clear()

this instance, making it empty.

Returns:Document

this instance.

containsback to summary
public boolean contains(final CharSequence sequence)

if at least one line in this instance contains the given sequence.

Note

each line is tested separately; no test is performed to see if the sequence spans more than one line.

Parameters
sequence:CharSequence

to test.

Returns:boolean

true if the condition holds, else false.

contentEqualsback to summary
public boolean contentEquals(final Document document)

if the given document has effectively the same content as this instance.

Parameters
document:Document

to test; may be null, which is treated as empty.

Returns:boolean

true if the content of the given document is equal to the content of this instance, as per List#equals(Object).

Annotations
@SuppressWarnings:AccessingNonPublicFieldOfAnotherObject
deleteSourceLineback to summary
public Document deleteSourceLine(final int index)

from this instance at the given index.

Parameters
index:int

at which to remove a line.

Returns:Document

this instance.

Exceptions
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= size())
getSourceLineback to summary
public String getSourceLine(final int index)

at the given index.

Parameters
index:int

at which to retrieve the line.

Returns:String

the line at the given index.

Exceptions
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= size())
insertSourceLineback to summary
public Document insertSourceLine(final int index, final String line)

at the specified index.

Parameters
index:int

at which the specified line is to be inserted

line:String

to be inserted

Returns:Document

this instance

Exceptions
NullPointerException:
if the specified line is null.
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= size())
isEmptyback to summary
public boolean isEmpty()

if this instance contains no lines.

Returns:boolean

true if size() == 0, else false.

isSupportedCharsetback to summary
public static boolean isSupportedCharset(final String charsetName)

for the given character set name.

Parameters
charsetName:String

to test; null returns false.

Returns:boolean

true if supported, else false.

loadback to summary
public Document load(final InputStream inputStream, final String encoding) throws IOException, IllegalArgumentException, NullPointerException

this instance from the given input stream using the given character encoding.

Note

it is the responsibility of the caller to close the input stream.

Parameters
inputStream:InputStream

from which to load; must not be null.

encoding:String

null for the system default.

Returns:Document

this object.

Exceptions
IOException:
if an I/O error occurs.
IllegalArgumentException:
if the encoding is not supported.
NullPointerException:
if the inputStream is null.
loadback to summary
public Document load(final Reader reader) throws IOException, NullPointerException

this instance from the given reader.

Note

it is the responsibility of the caller to close the reader.

Parameters
reader:Reader

from which to load; must not be null.

Returns:Document

this object.

Exceptions
IOException:
in an I/O error occurs.
NullPointerException:
if the reader is null.
loadback to summary
public Document load(final File file, final String encoding) throws IOException, IllegalArgumentException

this instance from the given file using the given character encoding.

Note

the underlying file input stream is closed automatically.

Parameters
file:File

from which to load; null is treated the empty path.

encoding:String

null for the system default.

Returns:Document

this object.

Exceptions
IOException:
in an I/O error occurs.
IllegalArgumentException:
if the encoding is not supported.
loadback to summary
public Document load(final String path, final String encoding) throws IOException, IllegalArgumentException

this instance from the given abstract file path using the given character encoding.

Note

the underlying file input stream is closed automatically.

Parameters
path:String

from which to load; null is treated the empty path.

encoding:String

null for the system default.

Returns:Document

this object.

Exceptions
IOException:
in an I/O error occurs.
IllegalArgumentException:
if the encoding is not supported.
loadback to summary
protected Document load(final Object source, final String encoding) throws IOException, NullPointerException, IllegalArgumentException

this instance from the given source.

Note

if the source is an InputStream or Reader, it is the responsibility of the caller to close; otherwise, the underlying file input stream is closed automatically.

Parameters
source:Object

required; by default, must be an instance of an InputStream, Reader, File, or String denoting an abstract file path.

encoding:String

optional; ignored if source is a Writer. null is taken to be Charset#defaultCharset().

Returns:Document

this instance.

Annotations
@SuppressWarnings:NestedAssignment
Exceptions
IOException:
if an I/O error occurs.
NullPointerException:
if source is null.
IllegalArgumentException:
if the encoding is not supported.
replaceWithback to summary
public Document replaceWith(final Document source)

as if by invoking this.clear().appendDocument(source).

Parameters
source:Document

content used to replace the existing content of this instance; may be null, which is treated as empty.

Returns:Document

this instance.

saveback to summary
public Document save(final OutputStream outputStream, final String encoding) throws IOException

to the given output stream using the given character encoding.

Note

it is the responsibility of the caller to close the output stream.

Parameters
outputStream:OutputStream

to which to save; must not be null.

encoding:String

null for the system default.

Returns:Document

this object.

Exceptions
IOException:
if an I/O error occurs.
IllegalArgumentException:
if the encoding is not supported.
NullPointerException:
if the output stream is null.
saveback to summary
public Document save(final File file, final String encoding) throws IOException, IllegalArgumentException

to the given file using the given character encoding.

Parameters
file:File

to which to save; null is treated as having an empty path

encoding:String

null for the system default.

Returns:Document

this object.

Exceptions
IOException:
if an I/O error occurs.
IllegalArgumentException:
if the encoding is not supported.
saveback to summary
public Document save(final String path, final String encoding) throws IOException, IllegalArgumentException

to the given abstract file path using the given character encoding.

Parameters
path:String

to which to save; null is treated as the empty path;

encoding:String

null for the system default.

Returns:Document

this object.

Exceptions
IOException:
if an I/O error occurs.
IllegalArgumentException:
if the encoding is not supported.
saveback to summary
public Document save(final Writer writer) throws IOException

to the given writer.

Note

it is the responsibility of the caller to close the writer.

Parameters
writer:Writer

to which to save; must not be null.

Returns:Document

this object.

Exceptions
IOException:
if an I/O error occurs.
NullPointerException:
if the writer is null.
saveback to summary
protected Document save(final Object target, final String encoding) throws IOException

this instance to the given target.

Note

if the target is an OutputStream or Writer, it is the responsibility of the caller to close; otherwise, the underlying file output stream is closed automatically.

Parameters
target:Object

required; by default, must be an instance of an OutputStream, Writer, File, or String denoting an abstract file path.

encoding:String

optional; does not apply to Writer. null is taken to be Charset#defaultCharset().

Returns:Document

this instance.

Exceptions
IOException:
if an I/O error occurs.
NullPointerException:
if target is null.
setSourceLineback to summary
public Document setSourceLine(final int index, final String line)

at the specified index in this instance.

Parameters
index:int

index of the line to replace

line:String

to be stored at the specified index

Returns:Document

this instance.

Exceptions
NullPointerException:
if the specified line is null.
IndexOutOfBoundsException:
if the index is out of range (index < 0 || index >= size())
sizeback to summary
public int size()

of this instance, as the number of lines.

Returns:int

the number of lines in this instance.