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.

Example:

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

Author:
Michael Angstadt
Specification Reference:
RFC 5545

Constructor Summary
ICalWriter(File file)
          Creates an iCalendar writer that writes to a file.
ICalWriter(File file, boolean append)
          Creates an iCalendar writer that writes to a file.
ICalWriter(File file, boolean append, FoldingScheme foldingScheme)
          Creates an iCalendar writer that writes to a file.
ICalWriter(File file, boolean append, 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.
 ICalMarshallerRegistrar getRegistrar()
          Gets the object that manages the component/property marshaller objects.
 boolean isCaretEncodingEnabled()
           Gets whether the writer will apply circumflex accent encoding on parameter values (disabled by default).
 void registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)
           Registers an experimental component marshaller.
 void registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)
           Registers an experimental property marshaller.
 void setCaretEncodingEnabled(boolean enable)
           Sets whether the writer will apply circumflex accent encoding on parameter values (disabled by default).
 void setRegistrar(ICalMarshallerRegistrar registrar)
          Sets the object that manages the component/property marshaller objects.
 void write(ICalendar ical)
          Writes an iCalendar object 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)
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

ICalWriter

public ICalWriter(OutputStream outputStream,
                  FoldingScheme foldingScheme,
                  String newline)
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

ICalWriter

public ICalWriter(File file)
           throws FileNotFoundException
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:
FileNotFoundException - if the file cannot be written to

ICalWriter

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

Parameters:
file - the file to write to
append - true to append to the end of the file, false to overwrite it
Throws:
FileNotFoundException - if the file cannot be written to

ICalWriter

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

Parameters:
file - the file to write to
append - true to append to the end of the file, false to overwrite it
foldingScheme - the folding scheme to use or null not to fold at all
Throws:
FileNotFoundException - if the file cannot be written to

ICalWriter

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

Parameters:
file - the file to write to
append - true to append to the end of the file, false to overwrite it
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use
Throws:
FileNotFoundException - 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

registerMarshaller

public void registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)

Registers an experimental property marshaller. Can also be used to override the marshaller of a standard property (such as DTSTART). Calling this method is the same as calling:

getRegistrar().register(marshaller).

Parameters:
marshaller - the marshaller to register

registerMarshaller

public void registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)

Registers an experimental component marshaller. Can also be used to override the marshaller of a standard component (such as VEVENT). Calling this method is the same as calling:

getRegistrar().register(marshaller).

Parameters:
marshaller - the marshaller to register

getRegistrar

public ICalMarshallerRegistrar getRegistrar()
Gets the object that manages the component/property marshaller objects.

Returns:
the marshaller registrar

setRegistrar

public void setRegistrar(ICalMarshallerRegistrar registrar)
Sets the object that manages the component/property marshaller objects.

Parameters:
registrar - the marshaller registrar

write

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

Parameters:
ical - the iCalendar object to write
Throws:
IllegalArgumentException - if the marshaller class for a component or property object cannot be found (only happens when an experimental property/component marshaller is not registered with the registerMarshaller method.)
IOException - if there's a problem writing to the data stream

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.