biweekly.io.json
Class JCalRawWriter

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

public class JCalRawWriter
extends Object
implements Closeable

Writes data to an iCalendar JSON data stream (jCal).

Author:
Michael Angstadt
See Also:
jCal draft

Constructor Summary
JCalRawWriter(Writer writer, boolean wrapInArray)
          Creates a new raw 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.
 boolean isIndent()
          Gets whether or not the JSON will be pretty-printed.
 void setIndent(boolean indent)
          Sets whether or not to pretty-print the JSON.
 void writeEndComponent()
          Closes the current component array.
 void writeProperty(String propertyName, ICalDataType dataType, JCalValue value)
          Writes a property to the current component.
 void writeProperty(String propertyName, ICalParameters parameters, ICalDataType dataType, JCalValue value)
          Writes a property to the current component.
 void writeStartComponent(String componentName)
          Writes the beginning of a new component array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JCalRawWriter

public JCalRawWriter(Writer writer,
                     boolean wrapInArray)
Creates a new raw writer.

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

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)

writeStartComponent

public void writeStartComponent(String componentName)
                         throws IOException
Writes the beginning of a new component array.

Parameters:
componentName - the component name (e.g. "vevent")
Throws:
IOException - if there's an I/O problem

writeEndComponent

public void writeEndComponent()
                       throws IOException
Closes the current component array.

Throws:
IllegalStateException - if there are no open components ( writeStartComponent(String) must be called first)
IOException - if there's an I/O problem

writeProperty

public void writeProperty(String propertyName,
                          ICalDataType dataType,
                          JCalValue value)
                   throws IOException
Writes a property to the current component.

Parameters:
propertyName - the property name (e.g. "version")
dataType - the property's data type (e.g. "text")
value - the property value
Throws:
IllegalStateException - if there are no open components ( writeStartComponent(String) must be called first) or if the last method called was writeEndComponent().
IOException - if there's an I/O problem

writeProperty

public void writeProperty(String propertyName,
                          ICalParameters parameters,
                          ICalDataType dataType,
                          JCalValue value)
                   throws IOException
Writes a property to the current component.

Parameters:
propertyName - the property name (e.g. "version")
parameters - the parameters
dataType - the property's data type (e.g. "text")
value - the property value
Throws:
IllegalStateException - if there are no open components ( writeStartComponent(String) must be called first) or if the last method called was writeEndComponent().
IOException - if there's an I/O problem

closeJsonStream

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

Throws:
IOException - if there's a problem closing the 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


Copyright © 2013 Michael Angstadt. All Rights Reserved.