public class VCardWriter extends StreamWriter implements Flushable
Writes VCard
objects to a plain-text vCard data stream.
Example:
VCard vcard1 = ... VCard vcard2 = ... Path file = Paths.get("vcard.vcf"); try (VCardWriter writer = new VCardWriter(file, VCardVersion.V3_0)) { writer.write(vcard1); writer.write(vcard2); }
Changing the line folding settings:
VCardWriter writer = new VCardWriter(...); //disable line folding writer.getVObjectWriter().getFoldedLineWriter().setLineLength(null); //change line length writer.getVObjectWriter().getFoldedLineWriter().setLineLength(50); //change folded line indent string writer.getVObjectWriter().getFoldedLineWriter().setIndent("\t");
addProdId, index, versionStrict
Constructor and Description |
---|
VCardWriter(OutputStream out,
VCardVersion targetVersion) |
VCardWriter(Path file,
boolean append,
VCardVersion targetVersion) |
VCardWriter(Path file,
VCardVersion targetVersion) |
VCardWriter(Writer writer,
VCardVersion targetVersion) |
Modifier and Type | Method and Description |
---|---|
protected void |
_write(VCard vcard,
List<VCardProperty> propertiesToAdd)
Writes a vCard to the stream.
|
void |
close()
Closes the output stream.
|
void |
flush()
Flushes the output stream.
|
TargetApplication |
getTargetApplication()
Gets the application that the vCards will be targeted for.
|
VCardVersion |
getTargetVersion()
Gets the version that the vCards should adhere to.
|
VObjectWriter |
getVObjectWriter()
Gets the writer that this object uses to write data to the output stream.
|
boolean |
isCaretEncodingEnabled()
Gets whether the writer will apply circumflex accent encoding on
parameter values (disabled by default).
|
Boolean |
isIncludeTrailingSemicolons()
Gets whether this writer will include trailing semicolon delimiters for
structured property values whose list of values end with null or empty
values.
|
void |
setCaretEncodingEnabled(boolean enable)
Sets whether the writer will apply circumflex accent encoding on
parameter values (disabled by default).
|
void |
setIncludeTrailingSemicolons(Boolean include)
Sets whether to include trailing semicolon delimiters for structured
property values whose list of values end with null or empty values.
|
void |
setTargetApplication(TargetApplication targetApplication)
Sets the application that the vCards will be targeted for.
|
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 totargetVersion
- the version that the vCards should conform to (if
set to "4.0", vCards will be written in UTF-8 encoding)public VCardWriter(Path file, VCardVersion targetVersion) throws IOException
file
- the file to write 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(Path file, boolean append, VCardVersion targetVersion) throws IOException
file
- the file to write 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 totargetVersion
- the version that the vCards should conform topublic VObjectWriter getVObjectWriter()
public VCardVersion getTargetVersion()
getTargetVersion
in class StreamWriter
public void setTargetVersion(VCardVersion targetVersion)
targetVersion
- the vCard versionpublic TargetApplication getTargetApplication()
Gets the application that the vCards will be targeted for.
Some vCard consumers do not completely adhere to the vCard specifications
and require their vCards to be formatted in a specific way. See the
TargetApplication
class for a list of these applications.
public void setTargetApplication(TargetApplication targetApplication)
Sets the application that the vCards will be targeted for.
Some vCard consumers do not completely adhere to the vCard specifications
and require their vCards to be formatted in a specific way. See the
TargetApplication
class for a list of these applications.
targetApplication
- the target application or null if the vCards do
not require any special processing (defaults to null)public Boolean isIncludeTrailingSemicolons()
Gets whether this writer will include trailing semicolon delimiters for
structured property values whose list of values end with null or empty
values. Examples of properties that use structured values are
StructuredName
and Address
.
This setting exists for compatibility reasons and should not make a difference to consumers that correctly implement the vCard grammar.
public void setIncludeTrailingSemicolons(Boolean include)
Sets whether to include trailing semicolon delimiters for structured
property values whose list of values end with null or empty values.
Examples of properties that use structured values are
StructuredName
and Address
.
This setting exists for compatibility reasons and should not make a difference to consumers that correctly implement the vCard grammar.
include
- true to include the trailing semicolons, false not to,
null to use the default behavior (defaults to false for vCard versions
2.1 and 3.0 and true for vCard version 4.0)public boolean isCaretEncodingEnabled()
Gets whether the writer will apply circumflex accent encoding on parameter values (disabled by default). This escaping mechanism allows for newlines and double quotes to be included in parameter values. It is only supported by vCard versions 3.0 and 4.0.
Note that this encoding mechanism is defined separately from the vCard specification and may not be supported by the consumer of the vCard.
VObjectWriter.isCaretEncodingEnabled()
public void setCaretEncodingEnabled(boolean enable)
Sets whether the writer will apply circumflex accent encoding on parameter values (disabled by default). This escaping mechanism allows for newlines and double quotes to be included in parameter values. It is only supported by vCard versions 3.0 and 4.0.
Note that this encoding mechanism is defined separately from the vCard specification and may not be supported by the consumer of the vCard.
enable
- true to use circumflex accent encoding, false not toVObjectWriter.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
flush
in interface Flushable
IOException
- if there's a problem flushing the output streampublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if there's a problem closing the output streamCopyright © 2012–2023 Michael Angstadt. All rights reserved.