ezvcard.io
Class VCardWriter

java.lang.Object
  extended by ezvcard.io.VCardWriter
All Implemented Interfaces:
Closeable

public class VCardWriter
extends Object
implements Closeable

Converts vCards to string representations.

Author:
Michael Angstadt

Constructor Summary
VCardWriter(File file)
          Creates a vCard writer (writes v3.0 vCards and uses the standard folding scheme and newline sequence).
VCardWriter(File file, VCardVersion targetVersion)
          Creates a vCard writer (uses the standard folding scheme and newline sequence).
VCardWriter(File file, VCardVersion targetVersion, FoldingScheme foldingScheme, String newline)
          Creates a vCard writer.
VCardWriter(OutputStream out)
          Creates a vCard writer (writes v3.0 vCards and uses the standard folding scheme and newline sequence).
VCardWriter(OutputStream out, VCardVersion targetVersion)
          Creates a vCard writer (uses the standard folding scheme and newline sequence).
VCardWriter(OutputStream out, VCardVersion targetVersion, FoldingScheme foldingScheme, String newline)
          Creates a vCard writer.
VCardWriter(Writer writer)
          Creates a vCard writer (writes v3.0 vCards and uses the standard folding scheme and newline sequence).
VCardWriter(Writer writer, VCardVersion targetVersion)
          Creates a vCard writer (uses the standard folding scheme and newline sequence).
VCardWriter(Writer writer, VCardVersion targetVersion, FoldingScheme foldingScheme, String newline)
          Creates a vCard writer.
 
Method Summary
 void close()
          Closes the underlying Writer object.
 CompatibilityMode getCompatibilityMode()
          Deprecated. 
 FoldingScheme getFoldingScheme()
          Gets the rules for how each line is folded.
 String getNewline()
          Gets the newline sequence that is used to separate lines.
 VCardVersion getTargetVersion()
          Gets the version that the vCards should adhere to.
 List<String> getWarnings()
          Gets the warnings from the last vCard that was marshalled.
 boolean isAddProdId()
          Gets whether or not a "PRODID" type will be added to each vCard, saying that the vCard was generated by this library.
 boolean isCaretEncodingEnabled()
           Gets whether the writer will use circumflex accent encoding for vCard 3.0 and 4.0 parameter values.
 void setAddProdId(boolean addProdId)
          Sets whether or not to add a "PRODID" type to each vCard, saying that the vCard was generated by this library.
 void setCaretEncodingEnabled(boolean enable)
           Sets whether the writer will use circumflex accent encoding for vCard 3.0 and 4.0 parameter values.
 void setCompatibilityMode(CompatibilityMode compatibilityMode)
          Deprecated. 
 void setTargetVersion(VCardVersion targetVersion)
          Sets the version that the vCards should adhere to.
 void write(VCard vcard)
          Writes a vCard
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VCardWriter

public VCardWriter(OutputStream out)
Creates a vCard writer (writes v3.0 vCards and uses the standard folding scheme and newline sequence).

Parameters:
out - the output stream to write the vCard to

VCardWriter

public VCardWriter(OutputStream out,
                   VCardVersion targetVersion)
Creates a vCard writer (uses the standard folding scheme and newline sequence).

Parameters:
out - the output stream to write the vCard to
targetVersion - the version that the vCards should conform to

VCardWriter

public VCardWriter(OutputStream out,
                   VCardVersion targetVersion,
                   FoldingScheme foldingScheme,
                   String newline)
Creates a vCard writer.

Parameters:
out - the output stream to write the vCard to
targetVersion - the version that the vCards should conform to
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use

VCardWriter

public VCardWriter(File file)
            throws IOException
Creates a vCard writer (writes v3.0 vCards and uses the standard folding scheme and newline sequence).

Parameters:
file - the file to write the vCard to
Throws:
IOException - if there's a problem opening the file

VCardWriter

public VCardWriter(File file,
                   VCardVersion targetVersion)
            throws IOException
Creates a vCard writer (uses the standard folding scheme and newline sequence).

Parameters:
file - the file to write the vCard to
targetVersion - the version that the vCards should conform to
Throws:
IOException - if there's a problem opening the file

VCardWriter

public VCardWriter(File file,
                   VCardVersion targetVersion,
                   FoldingScheme foldingScheme,
                   String newline)
            throws IOException
Creates a vCard writer.

Parameters:
file - the file to write the vCard to
targetVersion - the version that the vCards should conform to
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use
Throws:
IOException - if there's a problem opening the file

VCardWriter

public VCardWriter(Writer writer)
Creates a vCard writer (writes v3.0 vCards and uses the standard folding scheme and newline sequence).

Parameters:
writer - the writer to write the vCard to

VCardWriter

public VCardWriter(Writer writer,
                   VCardVersion targetVersion)
Creates a vCard writer (uses the standard folding scheme and newline sequence).

Parameters:
writer - the writer to write the vCard to
targetVersion - the version that the vCards should conform to

VCardWriter

public VCardWriter(Writer writer,
                   VCardVersion targetVersion,
                   FoldingScheme foldingScheme,
                   String newline)
Creates a vCard writer.

Parameters:
writer - the writer to write the vCard to
targetVersion - the version that the vCards should conform to
foldingScheme - the folding scheme to use or null not to fold at all
newline - the newline sequence to use
Method Detail

getCompatibilityMode

@Deprecated
public CompatibilityMode getCompatibilityMode()
Deprecated. 

Gets the compatibility mode. Used for customizing the marshalling process to target a particular application.

Returns:
the compatibility mode

setCompatibilityMode

@Deprecated
public void setCompatibilityMode(CompatibilityMode compatibilityMode)
Deprecated. 

Sets the compatibility mode. Used for customizing the marshalling process to target a particular application.

Parameters:
compatibilityMode - the compatibility mode

getTargetVersion

public VCardVersion getTargetVersion()
Gets the version that the vCards should adhere to.

Returns:
the vCard version

setTargetVersion

public void setTargetVersion(VCardVersion targetVersion)
Sets the version that the vCards should adhere to.

Parameters:
targetVersion - the vCard version

isAddProdId

public boolean isAddProdId()
Gets whether or not a "PRODID" type will be added to each vCard, saying that the vCard was generated by this library. For 2.1 vCards, the extended type "X-PRODID" will be added, since "PRODID" is not supported by that version.

Returns:
true if it will be added, false if not (defaults to true)

setAddProdId

public void setAddProdId(boolean addProdId)
Sets whether or not to add a "PRODID" type to each vCard, saying that the vCard was generated by this library. For 2.1 vCards, the extended type "X-PRODID" will be added, since "PRODID" is not supported by that version.

Parameters:
addProdId - true to add this type, false not to (defaults to true)

isCaretEncodingEnabled

public boolean isCaretEncodingEnabled()

Gets whether the writer will use circumflex accent encoding for vCard 3.0 and 4.0 parameter values. This escaping mechanism allows for newlines and double quotes to be included in parameter values.

Character Replacement
" ^'
newline ^n
^ ^^

This setting is disabled by default and is only used with 3.0 and 4.0 vCards. When writing a vCard with this setting disabled, newlines will be escaped as "\n", backslashes will be escaped as "\\", and double quotes will be replaced with single quotes.

Example:

 GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
  sburgh, PA 15212":geo: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 use circumflex accent encoding for vCard 3.0 and 4.0 parameter values. This escaping mechanism allows for newlines and double quotes to be included in parameter values.

Character Replacement
" ^'
newline ^n
^ ^^

This setting is disabled by default and is only used with 3.0 and 4.0 vCards. When writing a vCard with this setting disabled, newlines will be escaped as "\n", backslashes will be escaped as "\\", and double quotes will be replaced with single quotes.

Example:

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

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

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

getWarnings

public List<String> getWarnings()
Gets the warnings from the last vCard that was marshalled. This list is reset every time a new vCard is written.

Returns:
the warnings or empty list if there were no warnings

write

public void write(VCard vcard)
           throws IOException
Writes a vCard

Parameters:
vcard - the vCard to write
Throws:
IOException - if there's a problem writing to the output stream

close

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

Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2012-2013. All Rights Reserved.