biweekly.io.text
Class ICalWriter

java.lang.Object
  extended by biweekly.io.text.ICalWriter
All Implemented Interfaces:
Closeable

public class ICalWriter
extends Object
implements Closeable

Writes ICalendar objects to an iCalendar data stream.

 List<ICalendar> icals = ... 
 Writer writer = ...
 ICalWriter icalWriter = new ICalWriter(writer);
 for (ICalendar ical : icals){
   icalWriter.write(ical);
 }
 icalWriter.close();
 

Author:
Michael Angstadt

Constructor Summary
ICalWriter(File file)
          Creates an iCalendar writer that writes to a file.
ICalWriter(File file, FoldingScheme foldingScheme)
          Creates an iCalendar writer that writes to a file.
ICalWriter(File file, FoldingScheme foldingScheme, String newline)
          Creates an iCalendar writer that writes to a file.
ICalWriter(OutputStream outputStream)
          Creates an iCalendar writer that writes to an output stream.
ICalWriter(OutputStream outputStream, FoldingScheme foldingScheme)
          Creates an iCalendar writer that writes to an output stream.
ICalWriter(OutputStream outputStream, FoldingScheme foldingScheme, String newline)
          Creates an iCalendar writer that writes to an output stream.
ICalWriter(Writer writer)
          Creates an iCalendar writer that writes to a writer.
ICalWriter(Writer writer, FoldingScheme foldingScheme)
          Creates an iCalendar writer that writes to a writer.
ICalWriter(Writer writer, FoldingScheme foldingScheme, String newline)
          Creates an iCalendar writer that writes to a writer.
 
Method Summary
 void close()
          Closes the underlying Writer object.
 FoldingScheme getFoldingScheme()
          Gets the rules for how each line is folded.
 String getNewline()
          Gets the newline sequence that is used to separate lines.
 List<String> getWarnings()
          Gets the warnings from the last iCal that was written.
 boolean isCaretEncodingEnabled()
           Gets whether the writer will apply circumflex accent encoding on parameter values (disabled by default).
 void registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)
          Registers a marshaller for an experimental component.
 void registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)
          Registers a marshaller for an experimental property.
 void setCaretEncodingEnabled(boolean enable)
           Sets whether the writer will apply circumflex accent encoding on parameter values (disabled by default).
 void write(ICalendar ical)
          Writes an iCal to the data stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ICalWriter

public ICalWriter(OutputStream outputStream)
Creates an iCalendar writer that writes to an output stream. Uses the standard folding scheme and newline sequence.

Parameters:
outputStream - the output stream to write to

ICalWriter

public ICalWriter(OutputStream outputStream,
                  FoldingScheme foldingScheme)
           throws IOException
Creates an iCalendar writer that writes to an output stream. Uses the standard newline sequence.

Parameters:
outputStream - the output stream to write to
foldingScheme - the folding scheme to use or null not to fold at all
Throws:
IOException

ICalWriter

public ICalWriter(OutputStream outputStream,
                  FoldingScheme foldingScheme,
                  String newline)
           throws IOException
Creates an iCalendar writer that writes to an output stream.

Parameters:
outputStream - the output stream to write to
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use
Throws:
IOException

ICalWriter

public ICalWriter(File file)
           throws IOException
Creates an iCalendar writer that writes to a file. Uses the standard folding scheme and newline sequence.

Parameters:
file - the file to write to
Throws:
IOException - if the file cannot be written to

ICalWriter

public ICalWriter(File file,
                  FoldingScheme foldingScheme)
           throws IOException
Creates an iCalendar writer that writes to a file. Uses the standard newline sequence.

Parameters:
file - the file to write to
foldingScheme - the folding scheme to use or null not to fold at all
Throws:
IOException - if the file cannot be written to

ICalWriter

public ICalWriter(File file,
                  FoldingScheme foldingScheme,
                  String newline)
           throws IOException
Creates an iCalendar writer that writes to a file.

Parameters:
file - the file to write to
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use
Throws:
IOException - if the file cannot be written to

ICalWriter

public ICalWriter(Writer writer)
Creates an iCalendar writer that writes to a writer. Uses the standard folding scheme and newline sequence.

Parameters:
writer - the writer to the data stream

ICalWriter

public ICalWriter(Writer writer,
                  FoldingScheme foldingScheme)
Creates an iCalendar writer that writes to a writer. Uses the standard newline sequence.

Parameters:
writer - the writer to the data stream
foldingScheme - the folding scheme to use or null not to fold at all

ICalWriter

public ICalWriter(Writer writer,
                  FoldingScheme foldingScheme,
                  String newline)
Creates an iCalendar writer that writes to a writer.

Parameters:
writer - the writer to the data stream
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use
Method Detail

isCaretEncodingEnabled

public boolean isCaretEncodingEnabled()

Gets whether the writer will apply circumflex accent encoding on parameter values (disabled by default). This escaping mechanism allows for newlines and double quotes to be included in parameter values.

When disabled, the writer will replace newlines with spaces and double quotes with single quotes.

Returns:
true if circumflex accent encoding is enabled, false if not
See Also:
ICalRawWriter.isCaretEncodingEnabled()

setCaretEncodingEnabled

public void setCaretEncodingEnabled(boolean enable)

Sets whether the writer will apply circumflex accent encoding on parameter values (disabled by default). This escaping mechanism allows for newlines and double quotes to be included in parameter values.

When disabled, the writer will replace newlines with spaces and double quotes with single quotes.

Parameters:
enable - true to use circumflex accent encoding, false not to
See Also:
ICalRawWriter.setCaretEncodingEnabled(boolean)

getNewline

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

Returns:
the newline sequence

getFoldingScheme

public FoldingScheme getFoldingScheme()
Gets the rules for how each line is folded.

Returns:
the folding scheme or null if the lines are not folded

getWarnings

public List<String> getWarnings()
Gets the warnings from the last iCal that was written. This list is reset every time a new iCal is written.

Returns:
the warnings or empty list if there were no warnings

registerMarshaller

public void registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)
Registers a marshaller for an experimental property.

Parameters:
marshaller - the marshaller to register

registerMarshaller

public void registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)
Registers a marshaller for an experimental component.

Parameters:
marshaller - the marshaller to register

write

public void write(ICalendar ical)
           throws IOException
Writes an iCal to the data stream.

Parameters:
ical - the iCalendar object to write
Throws:
IOException

close

public void close()
           throws IOException
Closes the underlying Writer object.

Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2013 Michael Angstadt. All Rights Reserved.