public class JCalWriter extends StreamWriter implements Flushable
Writes ICalendar
objects to a JSON data stream (jCal).
Example:
List<ICalendar> icals = ... OutputStream out = ... JCalWriter jcalWriter = new JCalWriter(out); for (ICalendar ical : icals){ jcalWriter.write(ical); } jcalWriter.close();
Changing the timezone settings:
JCalWriter writer = new JCalWriter(...); //format all date/time values in a specific timezone instead of UTC //note: this makes an HTTP call to the "tzurl.org" website writer.getTimezoneInfo().setDefaultTimeZone(TimeZone.getDefault()); //format the value of a particular date/time property in a specific timezone instead of UTC //note: this makes an HTTP call to the "tzurl.org" website DateStart dtstart = ... writer.getTimezoneInfo().setTimeZone(dtstart, TimeZone.getDefault()); //generate Outlook-friendly VTIMEZONE components: writer.getTimezoneInfo().setGenerator(new TzUrlDotOrgGenerator(true));
context, index, tzinfo
Constructor and Description |
---|
JCalWriter(File file)
Creates a jCal writer that writes to a file.
|
JCalWriter(File file,
boolean wrapInArray)
Creates a jCal writer that writes to a file.
|
JCalWriter(OutputStream outputStream)
Creates a jCal writer that writes to an output stream.
|
JCalWriter(OutputStream outputStream,
boolean wrapInArray)
Creates a jCal writer that writes to an output stream.
|
JCalWriter(Writer writer)
Creates a jCal writer that writes to a writer.
|
JCalWriter(Writer writer,
boolean wrapInArray)
Creates a jCal writer that writes to a writer.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_write(ICalendar ical)
Writes an iCalendar object to the data stream.
|
void |
close()
Finishes writing the JSON document and closes the underlying
Writer object. |
void |
closeJsonStream()
Finishes writing the JSON document so that it is syntactically correct.
|
void |
flush()
Flushes the stream.
|
protected ICalVersion |
getTargetVersion()
Gets the version that the next iCalendar object will be written as.
|
boolean |
isIndent()
Gets whether or not the JSON will be pretty-printed.
|
void |
setIndent(boolean indent)
Sets whether or not to pretty-print the JSON.
|
getScribeIndex, getTimezoneInfo, registerScribe, registerScribe, setScribeIndex, setTimezoneInfo, write
public JCalWriter(OutputStream outputStream)
outputStream
- the output stream to write topublic JCalWriter(OutputStream outputStream, boolean wrapInArray)
outputStream
- the output stream to write towrapInArray
- true to wrap all iCalendar objects in a parent array,
false not to (useful when writing more than one iCalendar object)public JCalWriter(File file) throws IOException
file
- the file to write toIOException
- if the file cannot be written topublic JCalWriter(File file, boolean wrapInArray) throws IOException
file
- the file to write towrapInArray
- true to wrap all iCalendar objects in a parent array,
false not to (useful when writing more than one iCalendar object)IOException
- if the file cannot be written topublic JCalWriter(Writer writer)
writer
- the writer to the data streampublic JCalWriter(Writer writer, boolean wrapInArray)
writer
- the writer to the data streamwrapInArray
- true to wrap all iCalendar objects in a parent array,
false not to (useful when writing more than one iCalendar object)public boolean isIndent()
public void setIndent(boolean indent)
indent
- true to pretty-print it, false not to (defaults to false)protected void _write(ICalendar ical) throws IOException
StreamWriter
_write
in class StreamWriter
ical
- the iCalendar object to writeIOException
- if there's a problem writing to the data streamprotected ICalVersion getTargetVersion()
StreamWriter
getTargetVersion
in class StreamWriter
public void flush() throws IOException
flush
in interface Flushable
IOException
- if there's a problem flushing the streampublic void close() throws IOException
Writer
object.close
in interface Closeable
close
in interface AutoCloseable
IOException
- if there's a problem closing the streampublic void closeJsonStream() throws IOException
IOException
- if there's a problem writing to the data streamCopyright © 2013-2015 Michael Angstadt. All Rights Reserved.