biweekly
Class Biweekly

java.lang.Object
  extended by biweekly.Biweekly

public class Biweekly
extends Object

Contains static chaining factory methods for reading/writing iCalendar objects.

Writing an iCalendar object

 ICalendar ical = new ICalendar();
 
 //string
 String icalString = Biweekly.write(ical).go();
 
 //file
 File file = new File("meeting.ics");
 Biweekly.write(ical).go(file);
 
 //output stream
 OutputStream out = ...
 Biweekly.write(ical).go(out);
 out.close();
 
 //writer (should be configured to use UTF-8 encoding)
 Writer writer = ...
 Biweekly.write(ical).go(writer);
 writer.close();
 

Writing multiple iCalendar objects

 ICalendar ical1 = new ICalendar();
 ICalendar ical2 = new ICalendar();
 
 String icalString = Biweekly.write(ical1, ical2).go();
 

Writing an XML-encoded iCalendar object (xCal)

 //Call writeXml() instead of write()
 ICalendar ical = new ICalendar();
 String xml = Biweekly.writeXml(ical).indent(2).go();
 

Writing a JSON-encoded iCalendar object (jCal)

 //Call writeJson() instead of write()
 ICalendar ical = new ICalendar();
 String json = Biweekly.writeJson(ical).go();
 

Reading an iCalendar object

 ICalendar ical;
 
 //string
 String icalStr = ...
 ical = Biweekly.parse(icalStr).first();
 
 //file
 File file = new File("meeting.ics");
 ical = Biweekly.parse(file).first();
 
 //input stream
 InputStream in = ...
 ical = Biweekly.parse(in).first();
 in.close();  
 
 //reader (should be configured to read UTF-8)
 Reader reader = ...
 ical = Biweekly.parse(reader).first();
 reader.close();
 

Reading multiple iCalendar objects

 String icalStr = ...
 List<ICalendar> icals = Biweekly.parse(icalStr).all();
 

Reading an XML-encoded iCalendar object (xCal)

 //Call parseXml() instead of parse()
 String xml = ...
 ICalendar ical = Biweekly.parseXml(xml).first();
 

Reading a JSON-encoded iCalendar object (Cal)

 //Call parseJson() instead of parse()
 String json = ...
 ICalendar ical = Biweekly.parseJson(json).first();
 

Retrieving parser warnings

 String icalStr = ...
 List<List<String>> warnings = new ArrayList<List<String>>();
 List<ICalendar> icals = Biweekly.parse(icalStr).warnings(warnings).all();
 int i = 0;
 for (List<String> icalWarnings : warnings){
   System.out.println("iCal #" + (i++) + " warnings:");
   for (String warning : icalWarnings){
     System.out.println(warning);
   }
 }
 

The methods in this class make use of the following classes. These classes can be used if greater control over the read/write operation is required:

Classes Supports
streaming?
Text ICalReader / ICalWriter yes
XML XCalDocument no
JSON JCalReader / JCalWriter yes

Author:
Michael Angstadt

Nested Class Summary
static class Biweekly.ParserChainJsonReader
          Chainer class for parsing JSON-encoded iCalendar data streams (jCal).
static class Biweekly.ParserChainJsonString
          Chainer class for parsing JSON-encoded iCalendar strings (jCal).
static class Biweekly.ParserChainTextReader
          Chainer class for parsing plain text iCalendar data streams.
static class Biweekly.ParserChainTextString
          Chainer class for parsing plain text iCalendar strings.
static class Biweekly.ParserChainXmlDocument
          Chainer class for parsing XML-encoded iCalendar objects (xCal).
static class Biweekly.ParserChainXmlReader
          Chainer class for parsing XML-encoded iCalendar objects (xCal).
static class Biweekly.ParserChainXmlString
          Chainer class for parsing XML-encoded iCalendar objects (xCal).
static class Biweekly.WriterChainJson
          Chainer class for writing to JSON-encoded iCalendar data streams (jCal).
static class Biweekly.WriterChainText
          Chainer class for writing to plain text iCalendar data streams.
static class Biweekly.WriterChainXml
          Chainer class for writing xCal documents (XML-encoded iCalendar objects).
 
Field Summary
static String URL
          The project webpage.
static String VERSION
          The version of the library.
 
Method Summary
static Biweekly.ParserChainTextReader parse(File file)
          Parses an iCalendar file.
static Biweekly.ParserChainTextReader parse(InputStream in)
          Parses an iCalendar data stream.
static Biweekly.ParserChainTextReader parse(Reader reader)
          Parses an iCalendar data stream.
static Biweekly.ParserChainTextString parse(String ical)
          Parses an iCalendar object string.
static Biweekly.ParserChainJsonReader parseJson(File file)
          Parses a jCal data stream (JSON-encoded iCalendar objects).
static Biweekly.ParserChainJsonReader parseJson(InputStream in)
          Parses a jCal data stream (JSON-encoded iCalendar objects).
static Biweekly.ParserChainJsonReader parseJson(Reader reader)
          Parses a jCal data stream (JSON-encoded iCalendar objects).
static Biweekly.ParserChainJsonString parseJson(String json)
          Parses a jCal data stream (JSON-encoded iCalendar objects).
static Biweekly.ParserChainXmlDocument parseXml(Document document)
          Parses an xCal document (XML-encoded iCalendar objects).
static Biweekly.ParserChainXmlReader parseXml(File file)
          Parses an xCal document (XML-encoded iCalendar objects) from a file.
static Biweekly.ParserChainXmlReader parseXml(InputStream in)
          Parses an xCal document (XML-encoded iCalendar objects) from an input stream.
static Biweekly.ParserChainXmlReader parseXml(Reader reader)
           Parses an xCal document (XML-encoded iCalendar objects) from a reader.
static Biweekly.ParserChainXmlString parseXml(String xml)
          Parses an xCal document (XML-encoded iCalendar objects) from a string.
static Biweekly.WriterChainText write(Collection<ICalendar> icals)
          Writes multiple iCalendar objects to a data stream.
static Biweekly.WriterChainText write(ICalendar... icals)
          Writes multiple iCalendar objects to a data stream.
static Biweekly.WriterChainJson writeJson(Collection<ICalendar> icals)
          Writes an xCal document (XML-encoded iCalendar objects).
static Biweekly.WriterChainJson writeJson(ICalendar... icals)
          Writes an xCal document (XML-encoded iCalendar objects).
static Biweekly.WriterChainXml writeXml(Collection<ICalendar> icals)
          Writes an xCal document (XML-encoded iCalendar objects).
static Biweekly.WriterChainXml writeXml(ICalendar... icals)
          Writes an xCal document (XML-encoded iCalendar objects).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
The version of the library.


URL

public static final String URL
The project webpage.

Method Detail

parse

public static Biweekly.ParserChainTextString parse(String ical)
Parses an iCalendar object string.

Parameters:
ical - the iCalendar data
Returns:
chainer object for completing the parse operation

parse

public static Biweekly.ParserChainTextReader parse(File file)
Parses an iCalendar file.

Parameters:
file - the iCalendar file
Returns:
chainer object for completing the parse operation

parse

public static Biweekly.ParserChainTextReader parse(InputStream in)
Parses an iCalendar data stream.

Parameters:
in - the input stream
Returns:
chainer object for completing the parse operation

parse

public static Biweekly.ParserChainTextReader parse(Reader reader)
Parses an iCalendar data stream.

Parameters:
reader - the reader
Returns:
chainer object for completing the parse operation

write

public static Biweekly.WriterChainText write(ICalendar... icals)
Writes multiple iCalendar objects to a data stream.

Parameters:
icals - the iCalendar objects to write
Returns:
chainer object for completing the write operation

write

public static Biweekly.WriterChainText write(Collection<ICalendar> icals)
Writes multiple iCalendar objects to a data stream.

Parameters:
icals - the iCalendar objects to write
Returns:
chainer object for completing the write operation

parseXml

public static Biweekly.ParserChainXmlString parseXml(String xml)
Parses an xCal document (XML-encoded iCalendar objects) from a string.

Parameters:
xml - the XML string
Returns:
chainer object for completing the parse operation

parseXml

public static Biweekly.ParserChainXmlReader parseXml(File file)
Parses an xCal document (XML-encoded iCalendar objects) from a file.

Parameters:
file - the XML file
Returns:
chainer object for completing the parse operation

parseXml

public static Biweekly.ParserChainXmlReader parseXml(InputStream in)
Parses an xCal document (XML-encoded iCalendar objects) from an input stream.

Parameters:
in - the input stream
Returns:
chainer object for completing the parse operation

parseXml

public static Biweekly.ParserChainXmlReader parseXml(Reader reader)

Parses an xCal document (XML-encoded iCalendar objects) from a reader.

Note that use of this method is discouraged. It ignores the character encoding that is defined within the XML document itself, and should only be used if the encoding is undefined or if the encoding needs to be ignored for whatever reason. The parseXml(InputStream) method should be used instead, since it takes the XML document's character encoding into account when parsing.

Parameters:
reader - the reader
Returns:
chainer object for completing the parse operation

parseXml

public static Biweekly.ParserChainXmlDocument parseXml(Document document)
Parses an xCal document (XML-encoded iCalendar objects).

Parameters:
document - the XML document
Returns:
chainer object for completing the parse operation

writeXml

public static Biweekly.WriterChainXml writeXml(ICalendar... icals)
Writes an xCal document (XML-encoded iCalendar objects).

Parameters:
icals - the iCalendar object(s) to write
Returns:
chainer object for completing the write operation

writeXml

public static Biweekly.WriterChainXml writeXml(Collection<ICalendar> icals)
Writes an xCal document (XML-encoded iCalendar objects).

Parameters:
icals - the iCalendar objects to write
Returns:
chainer object for completing the write operation

parseJson

public static Biweekly.ParserChainJsonString parseJson(String json)
Parses a jCal data stream (JSON-encoded iCalendar objects).

Parameters:
json - the JSON data
Returns:
chainer object for completing the parse operation

parseJson

public static Biweekly.ParserChainJsonReader parseJson(File file)
Parses a jCal data stream (JSON-encoded iCalendar objects).

Parameters:
file - the JSON file
Returns:
chainer object for completing the parse operation

parseJson

public static Biweekly.ParserChainJsonReader parseJson(InputStream in)
Parses a jCal data stream (JSON-encoded iCalendar objects).

Parameters:
in - the input stream
Returns:
chainer object for completing the parse operation

parseJson

public static Biweekly.ParserChainJsonReader parseJson(Reader reader)
Parses a jCal data stream (JSON-encoded iCalendar objects).

Parameters:
reader - the reader
Returns:
chainer object for completing the parse operation

writeJson

public static Biweekly.WriterChainJson writeJson(ICalendar... icals)
Writes an xCal document (XML-encoded iCalendar objects).

Parameters:
icals - the iCalendar object(s) to write
Returns:
chainer object for completing the write operation

writeJson

public static Biweekly.WriterChainJson writeJson(Collection<ICalendar> icals)
Writes an xCal document (XML-encoded iCalendar objects).

Parameters:
icals - the iCalendar objects to write
Returns:
chainer object for completing the write operation


Copyright © 2013 Michael Angstadt. All Rights Reserved.