public class ICalWriter extends StreamWriter implements Flushable
Writes ICalendar
objects to an iCalendar data stream.
Example:
List<ICalendar> icals = ... OutputStream out = ... ICalWriter icalWriter = new ICalWriter(out, ICalVersion.V2_0); for (ICalendar ical : icals){ icalWriter.write(ical); } icalWriter.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)
Creates an iCalendar writer that writes to a file.
|
ICalWriter(File file,
ICalVersion version)
Creates an iCalendar writer that writes to a file.
|
ICalWriter(OutputStream outputStream,
ICalVersion version)
Creates an iCalendar writer that writes to an output stream.
|
ICalWriter(Writer writer,
ICalVersion version)
Creates an iCalendar 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()
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, write
public ICalWriter(OutputStream outputStream, ICalVersion version)
outputStream
- 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 output stream to write toversion
- the iCalendar version to adhere topublic ICalRawWriter getRawWriter()
public ICalVersion getTargetVersion()
getTargetVersion
in class StreamWriter
public 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 StreamWriter
ical
- the iCalendar object to writeIOException
- if there's a problem writing to the data streampublic 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
Copyright © 2013-2015 Michael Angstadt. All Rights Reserved.