public class JCardWriter extends StreamWriter implements Flushable
Writes VCard objects to a JSON data stream (jCard format).
Example:
VCard vcard1 = ...
VCard vcard2 = ...
Path file = Paths.get("vcard.json");
try (JCardWriter writer = new JCardWriter(file)) {
writer.write(vcard1);
writer.write(vcard2);
}
addProdId, index, versionStrict| Constructor and Description |
|---|
JCardWriter(com.fasterxml.jackson.core.JsonGenerator generator) |
JCardWriter(OutputStream out) |
JCardWriter(OutputStream out,
boolean wrapInArray) |
JCardWriter(Path file) |
JCardWriter(Path file,
boolean wrapInArray) |
JCardWriter(Writer writer) |
JCardWriter(Writer writer,
boolean wrapInArray) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_write(VCard vcard,
List<VCardProperty> properties)
Writes a vCard to the stream.
|
void |
close()
Ends the jCard data stream and closes the underlying writer.
|
void |
closeJsonStream()
Ends the jCard data stream, but does not close the underlying writer.
|
void |
flush()
Flushes the jCard data stream.
|
protected VCardVersion |
getTargetVersion()
Gets the version that the next vCard will be written as.
|
boolean |
isPrettyPrint()
Gets whether or not the JSON will be pretty-printed.
|
void |
setPrettyPrint(boolean prettyPrint)
Sets whether or not to pretty-print the JSON.
|
void |
setPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter prettyPrinter)
Sets the pretty printer to pretty-print the JSON with.
|
getScribeIndex, isAddProdId, isVersionStrict, registerScribe, setAddProdId, setScribeIndex, setVersionStrict, writepublic JCardWriter(OutputStream out)
out - the output stream to write to (UTF-8 encoding will be used)public JCardWriter(OutputStream out, boolean wrapInArray)
out - the output stream to write to (UTF-8 encoding will be used)wrapInArray - true to enclose all written vCards in a JSON array,
false not topublic JCardWriter(Path file) throws IOException
file - the file to write to (UTF-8 encoding will be used)IOException - if there's a problem opening the filepublic JCardWriter(Path file, boolean wrapInArray) throws IOException
file - the file to write to (UTF-8 encoding will be used)wrapInArray - true to enclose all written vCards in a JSON array,
false not toIOException - if there's a problem opening the filepublic JCardWriter(Writer writer)
writer - the writer to write topublic JCardWriter(Writer writer, boolean wrapInArray)
writer - the writer to write towrapInArray - true to enclose all written vCards in a JSON array,
false not topublic JCardWriter(com.fasterxml.jackson.core.JsonGenerator generator)
generator - the generator to write toprotected void _write(VCard vcard, List<VCardProperty> properties) throws IOException
_write in class StreamWritervcard - the vCard that is being writtenproperties - the properties to writeIOException - if there's a problem writing to the output streamIllegalArgumentException - if a scribe hasn't been registered for a
custom property class (see: registerScribe)protected VCardVersion getTargetVersion()
StreamWritergetTargetVersion in class StreamWriterpublic boolean isPrettyPrint()
public void setPrettyPrint(boolean prettyPrint)
prettyPrint - true to pretty-print it, false not to (defaults to
false)public void setPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter prettyPrinter)
setPrettyPrint(true) does
not also need to be called.prettyPrinter - the custom pretty printer (defaults to an instance
of JCardPrettyPrinter, if setPrettyPrint(true) has been
called.public void flush() throws IOException
flush in interface FlushableIOException - if there's a problem flushing the streampublic void closeJsonStream() throws IOException
IOException - if there's a problem closing the streampublic void close() throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if there's a problem closing the streamCopyright © 2012–2023 Michael Angstadt. All rights reserved.