public class ICalWriter extends StreamWriter implements Flushable
Writes ICalendar objects to a plain-text iCalendar data stream.
Example:
ICalendar ical1 = ...
ICalendar ical2 = ...
File file = new File("icals.ics");
ICalWriter writer = null;
try {
writer = new ICalWriter(file, ICalVersion.V2_0);
writer.write(ical1);
writer.write(ical2);
} finally {
if (writer != null) writer.close();
}
Changing the timezone settings:
ICalWriter writer = new ICalWriter(...); //format all date/time values in a specific timezone instead of UTC //note: this makes an HTTP call to "http://tzurl.org" writer.getTimezoneInfo().setDefaultTimeZone(TimeZone.getDefault()); //format the value of a single date/time property in a specific timezone instead of UTC //note: this makes an HTTP call to "http://tzurl.org" DateStart dtstart = ... writer.getTimezoneInfo().setTimeZone(dtstart, TimeZone.getDefault()); //generate Outlook-friendly VTIMEZONE components: writer.getTimezoneInfo().setGenerator(new TzUrlDotOrgGenerator(true));
Changing the line folding settings:
ICalWriter writer = new ICalWriter(...);
//disable line folding
writer.getRawWriter().getFoldedLineWriter().setLineLength(null);
//set line length (defaults to 75)
writer.getRawWriter().getFoldedLineWriter().setLineLength(50);
//change folded line indent string (defaults to one space character)
writer.getRawWriter().getFoldedLineWriter().setIndent("\t");
//change newline character (defaults to CRLF)
writer.getRawWriter().getFoldedLineWriter().setNewline("**");
context, index, tzinfo| Constructor and Description |
|---|
ICalWriter(File file,
boolean append,
ICalVersion version) |
ICalWriter(File file,
ICalVersion version) |
ICalWriter(OutputStream out,
ICalVersion version) |
ICalWriter(Writer writer,
ICalVersion version) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_write(ICalendar ical)
Writes an iCalendar object to the data stream.
|
void |
close()
Closes the underlying
Writer object. |
void |
flush()
Flushes the stream.
|
ICalRawWriter |
getRawWriter()
Gets the writer object that is used internally to write to the output
stream.
|
ICalVersion |
getTargetVersion()
Gets the version that the written iCalendar objects will adhere to.
|
boolean |
isCaretEncodingEnabled()
Gets whether the writer will apply circumflex accent encoding on
parameter values (disabled by default).
|
void |
setCaretEncodingEnabled(boolean enable)
Sets whether the writer will apply circumflex accent encoding on
parameter values (disabled by default).
|
void |
setTargetVersion(ICalVersion targetVersion)
Sets the version that the written iCalendar objects will adhere to.
|
getScribeIndex, getTimezoneInfo, registerScribe, registerScribe, setScribeIndex, setTimezoneInfo, writepublic ICalWriter(OutputStream out, ICalVersion version)
out - the output stream to write toversion - the iCalendar version to adhere topublic ICalWriter(File file, ICalVersion version) throws IOException
file - the file to write toversion - the iCalendar version to adhere toIOException - if the file cannot be written topublic ICalWriter(File file, boolean append, ICalVersion version) throws IOException
file - the file to write toversion - the iCalendar version to adhere toappend - true to append to the end of the file, false to overwrite
itIOException - if the file cannot be written topublic ICalWriter(Writer writer, ICalVersion version)
writer - the writer to write toversion - the iCalendar version to adhere topublic ICalRawWriter getRawWriter()
public ICalVersion getTargetVersion()
getTargetVersion in class StreamWriterpublic void setTargetVersion(ICalVersion targetVersion)
targetVersion - the iCalendar versionpublic 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.
When disabled, the writer will replace newlines with spaces and double quotes with single quotes.
ICalRawWriter.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.
When disabled, the writer will replace newlines with spaces and double quotes with single quotes.
enable - true to use circumflex accent encoding, false not toICalRawWriter.setCaretEncodingEnabled(boolean)protected void _write(ICalendar ical) throws IOException
StreamWriter_write in class StreamWriterical - the iCalendar object to writeIOException - if there's a problem writing to the data streampublic void flush() throws IOException
flush in interface FlushableIOException - if there's a problem flushing the streampublic void close() throws IOException
Writer object.close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2013-2015 Michael Angstadt. All Rights Reserved.