org.geotoolkit.io
Class IndentedLineWriter

Object
  extended by Writer
      extended by FilterWriter
          extended by IndentedLineWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
NumberedLineWriter

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

A writer that put some spaces in front of every lines. The indentation is initially set to 0 spaces. Users must invoke setIndentation(int) or setMargin(String) in order to set a different value.

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

Field Summary
 
Fields inherited from class FilterWriter
out
 
Fields inherited from class Writer
lock
 
Constructor Summary
IndentedLineWriter(Writer out)
          Constructs a stream which will add spaces in front of each line.
IndentedLineWriter(Writer out, int width)
          Constructs a stream which will the given amount of spaces in front of each line.
 
Method Summary
protected  void beginNewLine()
          Invoked when a new line is beginning.
 int getIdentation()
          Returns the current indentation.
 String getMargin()
          Returns the margin which is written at the beginning of every line.
 void setIndentation(int width)
          Sets the indentation to the specified value.
 void setMargin(String margin)
          Sets the margin to be written at the beginning of every line.
 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 FilterWriter
close, flush
 
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
 

Constructor Detail

IndentedLineWriter

public IndentedLineWriter(Writer out)
Constructs a stream which will add spaces in front of each line. The setIndentation(int) or setMargin(String) method must be invoked after this constructor in order to specify the amount of spaces to add.

Parameters:
out - The underlying stream to write to.

IndentedLineWriter

public IndentedLineWriter(Writer out,
                          int width)
Constructs a stream which will the given amount of spaces in front of each line. This is a convenience method invoking setIndentation(int) right after the construction.

Parameters:
out - The underlying stream to write to.
width - The indentation.
Since:
3.00
Method Detail

getIdentation

public int getIdentation()
Returns the current indentation. This is either the value given to the last call to setIndentation(int) method, or the length of the string given to the setMargin(String) method.

Returns:
The current indentation.

setIndentation

public void setIndentation(int width)
Sets the indentation to the specified value. This method will defines a margin as the given number of white spaces.

Parameters:
width - The number of space to insert at the beginning of every line.

getMargin

public String getMargin()
Returns the margin which is written at the beginning of every line. The default value is an empty string. This value can be modified either explicitely by a call to setMargin(String), or implicitly by a call to setIndentation(int).

Returns:
The string which is inserted at the beginning of every lines.
Since:
3.18

setMargin

public void setMargin(String margin)
Sets the margin to be written at the beginning of every line.

Parameters:
margin - The string to be inserted at the beginning of every lines.
Since:
3.18

beginNewLine

protected void beginNewLine()
                     throws IOException
Invoked when a new line is beginning. The default implementation writes the amount of spaces specified by the last call to setIndentation(int).

Throws:
IOException - If an I/O error occurs

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.

toString

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

Overrides:
toString in class Object


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