ezvcard.io.text
Class FoldedLineWriter

java.lang.Object
  extended by java.io.Writer
      extended by ezvcard.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, Integer lineLength, String indent, String newline)
          Creates a folded line writer.
 
Method Summary
 FoldedLineWriter append(CharSequence str, boolean quotedPrintable, Charset charset)
          Writes a string.
 void close()
          Closes the writer.
 void flush()
          Flushes the writer.
 Charset getEncoding()
          Gets the writer's character encoding.
 String getIndent()
          Gets the string that is prepended to each folded line.
 Integer 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.
 Writer getWriter()
          Gets the wrapped Writer object.
 void setIndent(String indent)
          Sets the string that is prepended to each folded line.
 void setLineLength(Integer 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[] cbuf, int off, int len)
           
 void write(char[] cbuf, int off, int len, boolean quotedPrintable, Charset charset)
          Writes a portion of an array of characters.
 void write(CharSequence str, boolean quotedPrintable, Charset charset)
          Writes a string.
 void writeln(String str)
          Writes a string, 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,
                        Integer lineLength,
                        String indent,
                        String newline)
Creates a folded line writer.

Parameters:
writer - the writer object to wrap
lineLength - the maximum length a line can be before it is folded (excluding the newline), or null disable folding
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, followed by a newline.

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

append

public FoldedLineWriter append(CharSequence str,
                               boolean quotedPrintable,
                               Charset charset)
                        throws IOException
Writes a string.

Parameters:
str - the string to write
quotedPrintable - true to encode the string in quoted-printable encoding, false not to
charset - the character set to use when encoding into quoted-printable, or null to use the writer's character encoding (only applicable if "quotedPrintable" is set to true)
Returns:
this
Throws:
IOException - if there's a problem writing to the output stream

write

public void write(CharSequence str,
                  boolean quotedPrintable,
                  Charset charset)
           throws IOException
Writes a string.

Parameters:
str - the string to write
quotedPrintable - true to encode the string in quoted-printable encoding, false not to
charset - the character set to use when encoding into quoted-printable, or null to use the writer's character encoding (only applicable if "quotedPrintable" is set to true)
Throws:
IOException - if there's a problem writing to the output stream

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len,
                  boolean quotedPrintable,
                  Charset charset)
           throws IOException
Writes a portion of an array of characters.

Parameters:
cbuf - the array of characters
off - the offset from which to start writing characters
len - the number of characters to write
quotedPrintable - true to encode the string in quoted-printable encoding, false not to
charset - the character set to use when encoding into quoted-printable, or null to use the writer's character encoding (only applicable if "quotedPrintable" is set to true)
Throws:
IOException - if there's a problem writing to the output stream

close

public void close()
           throws IOException
Closes the writer.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Flushes the writer.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

getLineLength

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

Returns:
the line length or null if folding is disabled

setLineLength

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

Parameters:
lineLength - the line length or null to disable folding
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

getWriter

public Writer getWriter()
Gets the wrapped Writer object.

Returns:
the wrapped writer

getEncoding

public Charset getEncoding()
Gets the writer's character encoding.

Returns:
the writer's character encoding or null if undefined


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.