ezvcard.io.text
Class VCardReader

java.lang.Object
  extended by ezvcard.io.text.VCardReader
All Implemented Interfaces:
Closeable

public class VCardReader
extends Object
implements Closeable

Parses VCard objects from a plain-text vCard data stream.

Example:

 File file = new File("vcards.vcf");
 VCardReader vcardReader = new VCardReader(file);
 VCard vcard;
 while ((vcard = vcardReader.readNext()) != null){
   ...
 }
 vcardReader.close();
 

Author:
Michael Angstadt

Constructor Summary
VCardReader(File file)
          Creates a reader that parses vCards from a file.
VCardReader(InputStream in)
          Creates a reader that parses vCards from an input stream.
VCardReader(Reader reader)
          Creates a reader that parses vCards from a reader.
VCardReader(String str)
          Creates a reader that parses vCards from a string.
 
Method Summary
 void close()
          Closes the underlying Reader object.
 Charset getDefaultQuotedPrintableCharset()
           Gets the character set to use when decoding quoted-printable values if the property has no CHARSET parameter, or if the CHARSET parameter is not a valid character set.
 ScribeIndex getScribeIndex()
          Gets the scribe index.
 List<String> getWarnings()
          Gets the warnings from the last vCard that was unmarshalled.
 boolean isCaretDecodingEnabled()
          Gets whether the reader will decode parameter values that use circumflex accent encoding (enabled by default).
 VCard readNext()
          Reads the next vCard from the data stream.
 void registerScribe(VCardPropertyScribe<? extends VCardProperty> scribe)
           Registers a property scribe.
 void setCaretDecodingEnabled(boolean enable)
          Sets whether the reader will decode parameter values that use circumflex accent encoding (enabled by default).
 void setDefaultQuotedPrintableCharset(Charset charset)
           Sets the character set to use when decoding quoted-printable values if the property has no CHARSET parameter, or if the CHARSET parameter is not a valid character set.
 void setScribeIndex(ScribeIndex index)
          Sets the scribe index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VCardReader

public VCardReader(String str)
Creates a reader that parses vCards from a string.

Parameters:
str - the string to read the vCards from

VCardReader

public VCardReader(InputStream in)
Creates a reader that parses vCards from an input stream.

Parameters:
in - the input stream to read the vCards from

VCardReader

public VCardReader(File file)
            throws FileNotFoundException
Creates a reader that parses vCards from a file.

Parameters:
file - the file to read the vCards from
Throws:
FileNotFoundException - if the file doesn't exist

VCardReader

public VCardReader(Reader reader)
Creates a reader that parses vCards from a reader.

Parameters:
reader - the reader to read the vCards from
Method Detail

isCaretDecodingEnabled

public boolean isCaretDecodingEnabled()
Gets whether the reader will decode parameter values that use circumflex accent encoding (enabled by default). This escaping mechanism allows newlines and double quotes to be included in parameter values.

Returns:
true if circumflex accent decoding is enabled, false if not
See Also:
VCardRawReader.isCaretDecodingEnabled()

setCaretDecodingEnabled

public void setCaretDecodingEnabled(boolean enable)
Sets whether the reader will decode parameter values that use circumflex accent encoding (enabled by default). This escaping mechanism allows newlines and double quotes to be included in parameter values.

Parameters:
enable - true to use circumflex accent decoding, false not to
See Also:
VCardRawReader.setCaretDecodingEnabled(boolean)

getDefaultQuotedPrintableCharset

public Charset getDefaultQuotedPrintableCharset()

Gets the character set to use when decoding quoted-printable values if the property has no CHARSET parameter, or if the CHARSET parameter is not a valid character set.

By default, the Reader's character encoding will be used. If the Reader has no character encoding, then the system's default character encoding will be used.

Returns:
the character set

setDefaultQuotedPrintableCharset

public void setDefaultQuotedPrintableCharset(Charset charset)

Sets the character set to use when decoding quoted-printable values if the property has no CHARSET parameter, or if the CHARSET parameter is not a valid character set.

By default, the Reader's character encoding will be used. If the Reader has no character encoding, then the system's default character encoding will be used.

Parameters:
charset - the character set

registerScribe

public void registerScribe(VCardPropertyScribe<? extends VCardProperty> scribe)

Registers a property scribe. This is the same as calling:

getScribeIndex().register(scribe)

Parameters:
scribe - the scribe to register

getScribeIndex

public ScribeIndex getScribeIndex()
Gets the scribe index.

Returns:
the scribe index

setScribeIndex

public void setScribeIndex(ScribeIndex index)
Sets the scribe index.

Parameters:
index - the scribe index

getWarnings

public List<String> getWarnings()
Gets the warnings from the last vCard that was unmarshalled. This list is reset every time a new vCard is read.

Returns:
the warnings or empty list if there were no warnings

readNext

public VCard readNext()
               throws IOException
Reads the next vCard from the data stream.

Returns:
the next vCard or null if there are no more
Throws:
IOException - if there's a problem reading from the stream

close

public void close()
           throws IOException
Closes the underlying Reader object.

Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.