public class VCardWriter extends StreamWriter implements Flushable
Writes VCard
objects to a plain-text vCard data stream.
Example:
VCard vcard1 = ... VCard vcard2 = ... File file = new File("vcard.vcf"); VCardWriter vcardWriter = new VCardWriter(file, VCardVersion.V3_0); vcardWriter.write(vcard1); vcardWriter.write(vcard2); vcardWriter.close();
Changing the line folding settings:
VCardWriter writer = new VCardWriter(...); //disable line folding writer.getRawWriter().getFoldedLineWriter().setLineLength(null); //change line length writer.getRawWriter().getFoldedLineWriter().setLineLength(50); //change folded line indent string writer.getRawWriter().getFoldedLineWriter().setIndent("\t"); //change newline character writer.getRawWriter().getFoldedLineWriter().setNewline("**");
addProdId, index, versionStrict
Constructor and Description |
---|
VCardWriter(File file,
boolean append,
VCardVersion targetVersion)
Creates a vCard writer.
|
VCardWriter(File file,
VCardVersion targetVersion)
Creates a vCard writer.
|
VCardWriter(OutputStream out,
VCardVersion targetVersion)
Creates a vCard writer.
|
VCardWriter(Writer writer,
VCardVersion targetVersion)
Creates a vCard writer.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_write(VCard vcard,
List<VCardProperty> propertiesToAdd)
Writes a vCard to the stream.
|
void |
close()
Closes the underlying
Writer object. |
void |
flush()
Flushes the underlying
Writer object. |
VCardRawWriter |
getRawWriter()
Gets the writer that this object wraps.
|
VCardVersion |
getTargetVersion()
Gets the version that the vCards should adhere 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 |
setTargetVersion(VCardVersion targetVersion)
Sets the version that the vCards should adhere to.
|
getScribeIndex, isAddProdId, isVersionStrict, registerScribe, setAddProdId, setScribeIndex, setVersionStrict, write
public VCardWriter(OutputStream out, VCardVersion targetVersion)
out
- the output stream to write the vCard totargetVersion
- the version that the vCards should conform to (if
set to "4.0", vCards will be written in UTF-8 encoding)public VCardWriter(File file, VCardVersion targetVersion) throws IOException
file
- the file to write the vCard totargetVersion
- the version that the vCards should conform to (if
set to "4.0", vCards will be written in UTF-8 encoding)IOException
- if there's a problem opening the filepublic VCardWriter(File file, boolean append, VCardVersion targetVersion) throws IOException
file
- the file to write the vCard toappend
- true to append to the end of the file, false to overwrite
ittargetVersion
- the version that the vCards should conform to (if
set to "4.0", vCards will be written in UTF-8 encoding)IOException
- if there's a problem opening the filepublic VCardWriter(Writer writer, VCardVersion targetVersion)
writer
- the writer to write the vCard totargetVersion
- the version that the vCards should conform topublic VCardRawWriter getRawWriter()
public VCardVersion getTargetVersion()
getTargetVersion
in class StreamWriter
public void setTargetVersion(VCardVersion targetVersion)
targetVersion
- the vCard versionpublic 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.
VCardRawWriter.isCaretEncodingEnabled()
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.
enable
- true to use circumflex accent encoding, false not toVCardRawWriter.setCaretEncodingEnabled(boolean)
protected void _write(VCard vcard, List<VCardProperty> propertiesToAdd) throws IOException
StreamWriter
_write
in class StreamWriter
vcard
- the vCard that is being writtenpropertiesToAdd
- the properties to writeIOException
- if there's a problem writing to the output streampublic void flush() throws IOException
Writer
object.flush
in interface Flushable
IOException
- if there's a problem flushing the writerpublic void close() throws IOException
Writer
object.close
in interface Closeable
close
in interface AutoCloseable
IOException
- if there's a problem closing the writerThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.