org.geotoolkit.io
Class LineWrapWriter

Object
  extended by Writer
      extended by FilterWriter
          extended by LineWrapWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

@ThreadSafe
@Decorator(value=java.io.Writer.class)
public class LineWrapWriter
extends FilterWriter

Wraps the lines at the specified maximal line length. The default line length is 80 characters. The maximal line length can be changed by a call to setMaximalLineLength(int).

Since:
3.00
Version:
3.00
Author:
Martin Desruisseaux (Geomatys)
Module:
utility/geotk-utility (download)    View source code for this class

Field Summary
static char HYPHEN
          Hyphen character.
static char SOFT_HYPHEN
          Hyphen character to be visible only if there is a line break to insert after it.
 
Fields inherited from class FilterWriter
out
 
Fields inherited from class Writer
lock
 
Constructor Summary
LineWrapWriter(Writer out)
          Constructs a stream which will wraps the lines at 80 characters.
LineWrapWriter(Writer out, int length)
          Constructs a stream which will wraps the lines at the given maximal amount of characters.
 
Method Summary
 void close()
          Sends pending characters to the underlying stream and close it.
 void flush()
          Sends pending characters to the underlying stream.
 int getMaximalLineLength()
          Returns the maximal line length.
 void setMaximalLineLength(int length)
          Sets the maximal line length.
 String toString()
          Returns a string representation if this writer.
 void write(char[] buffer, int offset, int length)
          Writes a portion of an array of characters.
 void write(int c)
          Writes a single character.
 void write(String string, int offset, int length)
          Writes a portion of a string.
 
Methods inherited from class Writer
append, append, append, write, write
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HYPHEN

public static final char HYPHEN
Hyphen character. Line break may be inserted after this character. The graphical symbol is similar to the usual '-' character. For non-breaking hyphen, use the '‑' character.

See Also:
Constant Field Values

SOFT_HYPHEN

public static final char SOFT_HYPHEN
Hyphen character to be visible only if there is a line break to insert after it. Otherwise this character is invisible. When visible, the graphical symbol is similar to the HYPHEN character.

This is equivalent to the HTML ­ entity.

See Also:
Constant Field Values
Constructor Detail

LineWrapWriter

public LineWrapWriter(Writer out)
Constructs a stream which will wraps the lines at 80 characters. The maximal line length can be changed by a call to setMaximalLineLength(int).

Parameters:
out - The underlying stream to write to.

LineWrapWriter

public LineWrapWriter(Writer out,
                      int length)
Constructs a stream which will wraps the lines at the given maximal amount of characters. This is a convenience constructor invoking setMaximalLineLength(int) immediately after construction.

Parameters:
out - The underlying stream to write to.
length - The maximal line length.
Method Detail

getMaximalLineLength

public int getMaximalLineLength()
Returns the maximal line length. The default value is 80.

Returns:
The current maximal line length.

setMaximalLineLength

public void setMaximalLineLength(int length)
Sets the maximal line length.

Parameters:
length - The new maximal line length.

write

public void write(int c)
           throws IOException
Writes a single character.

Overrides:
write in class FilterWriter
Throws:
IOException - If an I/O error occurs.

write

public void write(char[] buffer,
                  int offset,
                  int length)
           throws IOException
Writes a portion of an array of characters.

Overrides:
write in class FilterWriter
Parameters:
buffer - 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

public void write(String string,
                  int offset,
                  int length)
           throws IOException
Writes a portion of a string.

Overrides:
write in class FilterWriter
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

public void flush()
           throws IOException
Sends pending characters to the underlying stream. Note that this method should preferably be invoked at the end of a word, sentence or line, since invoking it may prevent LineWrapWriter to properly wrap the current line if it is in the middle of a word.

Invoking this method also flush the underlying stream. A cheapier way to send pending characters is to make sure that the last character is a line terminator ('\r' or '\n').

Specified by:
flush in interface Flushable
Overrides:
flush in class FilterWriter
Throws:
IOException - If an I/O error occurs.

close

public void close()
           throws IOException
Sends pending characters to the underlying stream and close it.

Specified by:
close in interface Closeable
Overrides:
close in class FilterWriter
Throws:
IOException - If an I/O error occurs.

toString

public String toString()
Returns a string representation if this writer.

Overrides:
toString in class Object


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.