ezvcard.io.json
Class JCardRawWriter

java.lang.Object
  extended by ezvcard.io.json.JCardRawWriter
All Implemented Interfaces:
Closeable, Flushable

public class JCardRawWriter
extends Object
implements Closeable, Flushable

Writes data to an vCard JSON data stream (jCard).

Author:
Michael Angstadt
See Also:
jCard draft

Constructor Summary
JCardRawWriter(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.
 void flush()
          Flushes the JSON stream.
 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 writeEndVCard()
          Closes the "vcard" component array.
 void writeProperty(String group, String propertyName, VCardParameters parameters, VCardDataType dataType, JCardValue value)
          Writes a property to the current vCard.
 void writeProperty(String propertyName, VCardDataType dataType, JCardValue value)
          Writes a property to the current component.
 void writeStartVCard()
          Writes the beginning of a new "vcard" component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JCardRawWriter

public JCardRawWriter(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 vCard)
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)

writeStartVCard

public void writeStartVCard()
                     throws IOException
Writes the beginning of a new "vcard" component.

Throws:
IOException - if there's an I/O problem

writeEndVCard

public void writeEndVCard()
                   throws IOException
Closes the "vcard" component array.

Throws:
IllegalStateException - if the component was never opened ( writeStartVCard() must be called first)
IOException - if there's an I/O problem

writeProperty

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

Parameters:
propertyName - the property name (e.g. "version")
dataType - the data type or null for "unknown"
value - the property value
Throws:
IllegalStateException - if the "vcard" component was never opened or was just closed (writeStartVCard() must be called first)
IOException - if there's an I/O problem

writeProperty

public void writeProperty(String group,
                          String propertyName,
                          VCardParameters parameters,
                          VCardDataType dataType,
                          JCardValue value)
                   throws IOException
Writes a property to the current vCard.

Parameters:
group - the group or null if there is no group
propertyName - the property name (e.g. "version")
parameters - the parameters
dataType - the data type or null for "unknown"
value - the property value
Throws:
IllegalStateException - if the "vcard" component was never opened or was just closed (writeStartVCard() must be called first)
IOException - if there's an I/O problem

flush

public void flush()
           throws IOException
Flushes the JSON stream.

Specified by:
flush in interface Flushable
Throws:
IOException

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 © 2012-2014 Michael Angstadt. All Rights Reserved.