biweekly.io.json
Class JCalWriter

java.lang.Object
  extended by biweekly.io.json.JCalWriter
All Implemented Interfaces:
Closeable

public class JCalWriter
extends Object
implements Closeable

Writes ICalendar objects to a JSON data stream (jCal).

Example:

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

Author:
Michael Angstadt
See Also:
jCal draft

Constructor Summary
JCalWriter(File file)
          Creates a jCal writer that writes to a file.
JCalWriter(File file, boolean wrapInArray)
          Creates a jCal writer that writes to a file.
JCalWriter(OutputStream outputStream)
          Creates a jCal writer that writes to an output stream.
JCalWriter(OutputStream outputStream, boolean wrapInArray)
          Creates a jCal writer that writes to an output stream.
JCalWriter(Writer writer)
          Creates a jCal writer that writes to a writer.
JCalWriter(Writer writer, boolean wrapInArray)
          Creates a jCal writer that writes to a writer.
 
Method Summary
 void close()
          Finishes writing the JSON document and closes the underlying Writer.
 void closeJsonStream()
          Finishes writing the JSON document so that it is syntactically correct.
 ICalMarshallerRegistrar getRegistrar()
          Gets the object that manages the component/property marshaller objects.
 boolean isIndent()
          Gets whether or not the JSON will be pretty-printed.
 void registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)
           Registers an experimental component marshaller.
 void registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)
           Registers an experimental property marshaller.
 void setIndent(boolean indent)
          Sets whether or not to pretty-print the JSON.
 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

JCalWriter

public JCalWriter(OutputStream outputStream)
Creates a jCal writer that writes to an output stream.

Parameters:
outputStream - the output stream to write to

JCalWriter

public JCalWriter(OutputStream outputStream,
                  boolean wrapInArray)
Creates a jCal writer that writes to an output stream.

Parameters:
outputStream - the output stream to write to
wrapInArray - true to wrap all iCalendar objects in a parent array, false not to (useful when writing more than one iCalendar object)

JCalWriter

public JCalWriter(File file)
           throws IOException
Creates a jCal writer that writes to a file.

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

JCalWriter

public JCalWriter(File file,
                  boolean wrapInArray)
           throws IOException
Creates a jCal writer that writes to a file.

Parameters:
file - the file to write to
wrapInArray - true to wrap all iCalendar objects in a parent array, false not to (useful when writing more than one iCalendar object)
Throws:
IOException - if the file cannot be written to

JCalWriter

public JCalWriter(Writer writer)
Creates a jCal writer that writes to a writer.

Parameters:
writer - the writer to the data stream

JCalWriter

public JCalWriter(Writer writer,
                  boolean wrapInArray)
Creates a jCal writer that writes to a writer.

Parameters:
writer - the writer to the data stream
wrapInArray - true to wrap all iCalendar objects in a parent array, false not to (useful when writing more than one iCalendar object)
Method Detail

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

isIndent

public boolean isIndent()
Gets whether or not the JSON will be pretty-printed.

Returns:
true if it will be pretty-printed, false if not (defaults to false)

setIndent

public void setIndent(boolean indent)
Sets whether or not to pretty-print the JSON.

Parameters:
indent - true to pretty-print it, false not to (defaults to false)

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
Finishes writing the JSON document and closes the underlying Writer.

Specified by:
close in interface Closeable
Throws:
IOException - if there's a problem closing the stream

closeJsonStream

public void closeJsonStream()
                     throws IOException
Finishes writing the JSON document so that it is syntactically correct. No more iCalendar objects can be written once this method is called.

Throws:
IOException - if there's a problem writing to the data stream


Copyright © 2013 Michael Angstadt. All Rights Reserved.