ezvcard.io.text
Class VCardRawWriter

java.lang.Object
  extended by ezvcard.io.text.VCardRawWriter
All Implemented Interfaces:
Closeable, Flushable

public class VCardRawWriter
extends Object
implements Closeable, Flushable

Writes data to an vCard data stream.

Author:
Michael Angstadt

Nested Class Summary
static interface VCardRawWriter.ProblemsListener
          A listener whose methods are invoked when non-critical issues occur during the writing process.
 
Constructor Summary
VCardRawWriter(Writer writer, VCardVersion version)
          Creates a vCard raw writer using the standard folding scheme and newline sequence.
VCardRawWriter(Writer writer, VCardVersion version, FoldingScheme foldingScheme)
          Creates a vCard raw writer using the standard newline sequence.
VCardRawWriter(Writer writer, VCardVersion version, FoldingScheme foldingScheme, String newline)
          Creates a vCard raw writer.
 
Method Summary
 void close()
          Closes the underlying Writer object.
 void flush()
          Flushes 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.
 VCardRawWriter.ProblemsListener getProblemsListener()
          Gets the problems listener.
 VCardVersion getVersion()
          Gets the vCard version that the writer is adhering to.
 boolean isCaretEncodingEnabled()
           Gets whether the writer will apply circumflex accent encoding on parameter values (disabled by default, only applies to 3.0 and 4.0 vCards).
 void setCaretEncodingEnabled(boolean enable)
           Sets whether the writer will apply circumflex accent encoding on parameter values (disabled by default, only applies to 3.0 and 4.0 vCards).
 void setProblemsListener(VCardRawWriter.ProblemsListener problemsListener)
          Sets the problems listener.
 void setVersion(VCardVersion version)
          Sets the vCard version that the writer should adhere to.
 void writeBeginComponent(String componentName)
          Writes a property marking the beginning of a component (in other words, writes a "BEGIN:NAME" property).
 void writeEndComponent(String componentName)
          Writes a property marking the end of a component (in other words, writes a "END:NAME" property).
 void writeProperty(String propertyName, String value)
          Writes a property to the vCard data stream.
 void writeProperty(String group, String propertyName, VCardParameters parameters, String value)
          Writes a property to the vCard data stream.
 void writeVersion()
          Writes a "VERSION" property, based on the vCard version that the writer is adhering to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VCardRawWriter

public VCardRawWriter(Writer writer,
                      VCardVersion version)
Creates a vCard raw writer using the standard folding scheme and newline sequence.

Parameters:
writer - the writer to the data stream
version - the vCard version to adhere to

VCardRawWriter

public VCardRawWriter(Writer writer,
                      VCardVersion version,
                      FoldingScheme foldingScheme)
Creates a vCard raw writer using the standard newline sequence.

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

VCardRawWriter

public VCardRawWriter(Writer writer,
                      VCardVersion version,
                      FoldingScheme foldingScheme,
                      String newline)
Creates a vCard raw writer.

Parameters:
writer - the writer to the data stream
version - the vCard version to adhere to
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, only applies to 3.0 and 4.0 vCards). 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.

Character Replacement
(when disabled)
Replacement
(when enabled)
" ' ^'
newline space ^n
^ ^ ^^

Example:

 GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
  sburgh, PA 15212":40.446816;80.00566
 

Returns:
true if circumflex accent encoding is enabled, false if not
See Also:
RFC 6868

setCaretEncodingEnabled

public void setCaretEncodingEnabled(boolean enable)

Sets whether the writer will apply circumflex accent encoding on parameter values (disabled by default, only applies to 3.0 and 4.0 vCards). 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.

Character Replacement
(when disabled)
Replacement
(when enabled)
" ' ^'
newline space ^n
^ ^ ^^

Example:

 GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
  sburgh, PA 15212":40.446816;80.00566
 

Parameters:
enable - true to use circumflex accent encoding, false not to
See Also:
RFC 6868

getVersion

public VCardVersion getVersion()
Gets the vCard version that the writer is adhering to.

Returns:
the version

setVersion

public void setVersion(VCardVersion version)
Sets the vCard version that the writer should adhere to.

Parameters:
version - the version

getNewline

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

Returns:
the newline sequence

getProblemsListener

public VCardRawWriter.ProblemsListener getProblemsListener()
Gets the problems listener.

Returns:
the listener or null if not set

setProblemsListener

public void setProblemsListener(VCardRawWriter.ProblemsListener problemsListener)
Sets the problems listener.

Parameters:
problemsListener - the listener or null to remove

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

writeBeginComponent

public void writeBeginComponent(String componentName)
                         throws IOException
Writes a property marking the beginning of a component (in other words, writes a "BEGIN:NAME" property).

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

writeEndComponent

public void writeEndComponent(String componentName)
                       throws IOException
Writes a property marking the end of a component (in other words, writes a "END:NAME" property).

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

writeVersion

public void writeVersion()
                  throws IOException
Writes a "VERSION" property, based on the vCard version that the writer is adhering to.

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

writeProperty

public void writeProperty(String propertyName,
                          String value)
                   throws IOException
Writes a property to the vCard data stream.

Parameters:
propertyName - the property name (e.g. "FN")
value - the property value
Throws:
IllegalArgumentException - if the property name contains invalid characters
IOException - if there's an I/O problem

writeProperty

public void writeProperty(String group,
                          String propertyName,
                          VCardParameters parameters,
                          String value)
                   throws IOException
Writes a property to the vCard data stream.

Parameters:
group - the group or null if there is no group
propertyName - the property name (e.g. "FN")
parameters - the property parameters
value - the property value (will be converted to "quoted-printable" encoding if the Encoding.QUOTED_PRINTABLE parameter is set)
Throws:
IllegalArgumentException - if the group or property name contains invalid characters
IOException - if there's an I/O problem

flush

public void flush()
           throws IOException
Flushes the underlying Writer object.

Specified by:
flush in interface Flushable
Throws:
IOException - if there's a problem flushing the writer

close

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

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


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.