biweekly.io.text
Class FoldedLineWriter

java.lang.Object
  extended by java.io.Writer
      extended by biweekly.io.text.FoldedLineWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class FoldedLineWriter
extends Writer

Automatically folds lines as they are written.

Author:
Michael Angstadt

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
FoldedLineWriter(Writer writer, int lineLength, String indent, String newline)
           
 
Method Summary
 void close()
           
 void flush()
           
 String getIndent()
          Gets the string that is prepended to each folded line.
 int getLineLength()
          Gets the maximum length a line can be before it is folded (excluding the newline).
 String getNewline()
          Gets the newline sequence that is used to separate lines.
 void setIndent(String indent)
          Sets the string that is prepended to each folded line.
 void setLineLength(int lineLength)
          Sets the maximum length a line can be before it is folded (excluding the newline).
 void setNewline(String newline)
          Sets the newline sequence that is used to separate lines
 void write(char[] buf, int start, int end)
           
 void write(char[] buf, int start, int end, int lineLength, String indent)
          Writes a portion of an array of characters.
 void writeln(String str)
          Writes a string of text, followed by a newline.
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FoldedLineWriter

public FoldedLineWriter(Writer writer,
                        int lineLength,
                        String indent,
                        String newline)
Parameters:
writer - the writer object to wrap
lineLength - the maximum length a line can be before it is folded (excluding the newline)
indent - the string to prepend to each folded line (e.g. a single space character)
newline - the newline sequence to use (e.g. "\r\n")
Throws:
IllegalArgumentException - if the line length is less than or equal to zero
IllegalArgumentException - if the length of the indent string is greater than the max line length
Method Detail

writeln

public void writeln(String str)
             throws IOException
Writes a string of text, followed by a newline.

Parameters:
str - the text to write
Throws:
IOException - if there's a problem writing to the output stream

write

public void write(char[] buf,
                  int start,
                  int end)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException

write

public void write(char[] buf,
                  int start,
                  int end,
                  int lineLength,
                  String indent)
           throws IOException
Writes a portion of an array of characters.

Parameters:
buf - the array of characters
start - the offset from which to start writing characters
end - the number of characters to write
lineLength - the maximum length a line can be before it is folded (excluding the newline)
indent - the indent string to use (e.g. a single space character)
Throws:
IOException - if there's a problem writing to the output stream

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

getLineLength

public int getLineLength()
Gets the maximum length a line can be before it is folded (excluding the newline).

Returns:
the line length

setLineLength

public void setLineLength(int lineLength)
Sets the maximum length a line can be before it is folded (excluding the newline).

Parameters:
lineLength - the line length
Throws:
IllegalArgumentException - if the line length is less than or equal to zero

getIndent

public String getIndent()
Gets the string that is prepended to each folded line.

Returns:
the indent string

setIndent

public void setIndent(String indent)
Sets the string that is prepended to each folded line.

Parameters:
indent - the indent string (e.g. a single space character)
Throws:
IllegalArgumentException - if the length of the indent string is greater than the max line length

getNewline

public String getNewline()
Gets the newline sequence that is used to separate lines.

Returns:
the newline sequence

setNewline

public void setNewline(String newline)
Sets the newline sequence that is used to separate lines

Parameters:
newline - the newline sequence


Copyright © 2013 Michael Angstadt. All Rights Reserved.