Package org.geotools.util
Class LineWriter
Object
Writer
FilterWriter
LineWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
Writes characters to a stream while replacing various EOL by a unique string. This class catches all occurrences of
"\r", "\n" and "\r\n", and replaces them by the platform depend EOL string ("\r\n" on
Windows, "\n" on Unix), or any other EOL explicitly set at construction time. This writer also remove
trailing blanks before end of lines, but this behavior can be changed by overriding isWhitespace(char).- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
-
Field Summary
Fields inherited from class FilterWriter
out -
Constructor Summary
ConstructorsConstructorDescriptionLineWriter(Writer out) Constructs aLineWriterobject that will use the platform dependent line separator.LineWriter(Writer out, String lineSeparator) Constructs aLineWriterobject that will use the specified line separator. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Flushs the stream's content to the underlying stream.Returns the current line separator.protected booleanisWhitespace(char c) Returnstrueif the specified character is a white space that can be ignored on end of line.voidsetLineSeparator(String lineSeparator) Changes the line separator.voidwrite(char[] cbuf, int offset, int length) Writes a portion of an array of characters.voidwrite(int c) Writes a single character.voidWrites a portion of an array of a string.Methods inherited from class FilterWriter
close
-
Constructor Details
-
LineWriter
Constructs aLineWriterobject that will use the platform dependent line separator.- Parameters:
out- A writer object to provide the underlying stream.- Throws:
IllegalArgumentException- ifoutisnull.
-
LineWriter
Constructs aLineWriterobject that will use the specified line separator.- Parameters:
out- A writer object to provide the underlying stream.lineSeparator- String to use as line separator.- Throws:
IllegalArgumentException- ifoutorlineSeparatorisnull.
-
-
Method Details
-
getLineSeparator
Returns the current line separator.- Returns:
- The current line separator.
-
setLineSeparator
Changes the line separator. This is the string to insert in place of every occurences of"\r","\n"or"\r\n".- Parameters:
lineSeparator- The new line separator.- Throws:
IllegalArgumentException- IflineSeparatorisnull.
-
write
Writes a single character.- Overrides:
writein classFilterWriter- Throws:
IOException- If an I/O error occurs.
-
write
Writes a portion of an array of characters.- Overrides:
writein classFilterWriter- Parameters:
cbuf- Buffer of characters to be written.offset- Offset from which to start reading characters.length- Number of characters to be written.- Throws:
IOException- If an I/O error occurs.
-
write
Writes a portion of an array of a string.- Overrides:
writein classFilterWriter- Parameters:
string- String to be written.offset- Offset from which to start reading characters.length- Number of characters to be written.- Throws:
IOException- If an I/O error occurs.
-
flush
Flushs the stream's content to the underlying stream. This method flush completly all internal buffers, including any whitespace characters that should have been skipped if the next non-blank character is a line separator.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterWriter- Throws:
IOException- If an I/O error occurs.
-
isWhitespace
Returnstrueif the specified character is a white space that can be ignored on end of line. The default implementation returnsCharacter.isSpaceChar(char). Subclasses can override this method in order to change the criterion.- Parameters:
c- The character to test.- Returns:
trueifcis a character that can be ignored on end of line.- Throws:
IOException- if this method can not determine if the character is ignoreable.- Since:
- 2.5
-