net.sf.plist.io.bin
Class BinaryParser

java.lang.Object
  extended by net.sf.plist.io.PropertyListParser
      extended by net.sf.plist.io.bin.BinaryParser

public class BinaryParser
extends PropertyListParser

Parses binary property list files to a tree consisting of NSObjects


Field Summary
static byte ARRAY
          Byte mask indicating a array value
static Charset ASCIICHARSET
          Charset to parse ASCII strings
static byte ASCIISTRING
          Byte mask indicating a ascii string value
static byte BOOLFALSE
          Byte indicating a Boolean.FALSE value
static byte BOOLTRUE
          Byte indicating a Boolean.TRUE value
static byte DATA
          Byte mask indicating a binary data value
static byte DATE
          Byte mask indicating a date value
static byte DICT
          Byte mask indicating a dictionary value
protected static byte[] ENDMAGIC
          Bytes expected near the end of the file
static long EPOCH
          Epoch constant, used to calculate dates
static byte FILL
          Filler byte
static byte INT
          Byte mask indicating a integer value
static byte LENMASK
          Mask for extracting the length
static byte NULL
          NULL byte
protected  int numObjects
          Number of objects in stream
static byte OBJMASK
          Mask for extracting the objecttype (result must be shifted right 4 bits)
protected  byte objRefSize
          Size of object references in bytes
protected  byte offsetEntrySize
          Size of offset entries in bytes
protected  int[] offsetTable
          The offset table
protected  long offsetTableOffset
          Starting address of the offset table
static byte REAL
          Byte mask indicating a real value
protected  long rootAddr
          Starting address of the root object
static byte SET
          Byte mask indicating a set value (not implemented)
protected static byte[] STARTMAGIC
          Bytes expected at the start of the file
static byte UID
          Byte mask indicating a uid value (not implemented)
static Charset UNICODECHARSET
          Charset to parse unicode strings
static byte UNICODESTRING
          Byte mask indicating a unicode string value
 
Fields inherited from class net.sf.plist.io.PropertyListParser
file, input
 
Constructor Summary
BinaryParser(File file)
           
BinaryParser(InputStream input)
          Not supported yet.
 
Method Summary
static int getInteger(byte... bytes)
          Convert an array of bytes to a integer
protected  int getLength(byte lengthMask)
          Read the length When the lengthMask is 0xF (0000 1111), an integer follows containing the actual length lengthMask must be equal or smaller than LENMASK
static long getLong(byte... bytes)
          Convert an array of bytes to a long
 NSObject parse()
          Parse the property list to a tree
protected  NSArray parseArray(byte length)
          Parse a node to a NSArray on a given start address
protected  NSString parseASCII(byte length)
          Parse a node to a NSString on a given start address, parsing with an ASCII charset
protected  NSData parseData(byte length)
          Parse a node to a NSData on a given start address
protected  NSDate parseDate(byte length)
          Parse a node to a NSDate on a given start address
protected  NSDictionary parseDictionary(byte length)
          Parse a node to a NSDictionary on a given start address
protected  NSInteger parseInteger(byte length)
          Parse a node to a NSInteger on a given start address
protected  NSObject parseNode(long addr)
          Parse a node to a NSObject on a given start address
protected  NSReal parseReal(byte length)
          Parse a node to a NSReal on a given start address
protected  NSObject parseSet(byte length)
          Parse a NSSet (not implemented)
protected  NSObject parseUid(byte length)
          Parse a NSUID (not implemented)
protected  NSString parseUnicode(byte length)
          Parse a node to a NSString on a given start address, parsing with an unicode charset
 
Methods inherited from class net.sf.plist.io.PropertyListParser
parse, parse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final byte NULL
NULL byte

See Also:
Constant Field Values

BOOLFALSE

public static final byte BOOLFALSE
Byte indicating a Boolean.FALSE value

See Also:
Constant Field Values

BOOLTRUE

public static final byte BOOLTRUE
Byte indicating a Boolean.TRUE value

See Also:
Constant Field Values

FILL

public static final byte FILL
Filler byte

See Also:
Constant Field Values

INT

public static final byte INT
Byte mask indicating a integer value

See Also:
Constant Field Values

REAL

public static final byte REAL
Byte mask indicating a real value

See Also:
Constant Field Values

DATE

public static final byte DATE
Byte mask indicating a date value

See Also:
Constant Field Values

DATA

public static final byte DATA
Byte mask indicating a binary data value

See Also:
Constant Field Values

ASCIISTRING

public static final byte ASCIISTRING
Byte mask indicating a ascii string value

See Also:
Constant Field Values

UNICODESTRING

public static final byte UNICODESTRING
Byte mask indicating a unicode string value

See Also:
Constant Field Values

UID

public static final byte UID
Byte mask indicating a uid value (not implemented)

See Also:
Constant Field Values

ARRAY

public static final byte ARRAY
Byte mask indicating a array value

See Also:
Constant Field Values

SET

public static final byte SET
Byte mask indicating a set value (not implemented)

See Also:
Constant Field Values

DICT

public static final byte DICT
Byte mask indicating a dictionary value

See Also:
Constant Field Values

OBJMASK

public static final byte OBJMASK
Mask for extracting the objecttype (result must be shifted right 4 bits)

See Also:
Constant Field Values

LENMASK

public static final byte LENMASK
Mask for extracting the length

See Also:
Constant Field Values

STARTMAGIC

protected static final byte[] STARTMAGIC
Bytes expected at the start of the file


ENDMAGIC

protected static final byte[] ENDMAGIC
Bytes expected near the end of the file


ASCIICHARSET

public static final Charset ASCIICHARSET
Charset to parse ASCII strings


UNICODECHARSET

public static final Charset UNICODECHARSET
Charset to parse unicode strings


EPOCH

public static final long EPOCH
Epoch constant, used to calculate dates

See Also:
Constant Field Values

offsetEntrySize

protected final byte offsetEntrySize
Size of offset entries in bytes


objRefSize

protected final byte objRefSize
Size of object references in bytes


numObjects

protected final int numObjects
Number of objects in stream


rootAddr

protected final long rootAddr
Starting address of the root object


offsetTableOffset

protected final long offsetTableOffset
Starting address of the offset table


offsetTable

protected final int[] offsetTable
The offset table

Constructor Detail

BinaryParser

public BinaryParser(File file)
             throws IOException,
                    PropertyListException
Throws:
IOException
PropertyListException
See Also:
PropertyListParser.PropertyListParser(File)

BinaryParser

public BinaryParser(InputStream input)
Not supported yet.

Throws:
UnsupportedOperationException - because this is not supported yet
Method Detail

getLong

public static long getLong(byte... bytes)
Convert an array of bytes to a long

Parameters:
bytes - the byte array (8 bytes max)
Returns:
the long

getInteger

public static int getInteger(byte... bytes)
Convert an array of bytes to a integer

Parameters:
bytes - the byte array (4 bytes max)
Returns:
the int

parse

public NSObject parse()
               throws PropertyListException
Parse the property list to a tree

Specified by:
parse in class PropertyListParser
Returns:
the root NSObject of the parsed property list
Throws:
PropertyListException - when parsing the property list failed for some reason

parseNode

protected NSObject parseNode(long addr)
                      throws IOException,
                             PropertyListException
Parse a node to a NSObject on a given start address

Parameters:
addr - the start address
Returns:
the NSObject
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseInteger

protected NSInteger parseInteger(byte length)
                          throws IOException
Parse a node to a NSInteger on a given start address

Parameters:
length - the length byte
Returns:
the NSInteger
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseReal

protected NSReal parseReal(byte length)
                    throws IOException
Parse a node to a NSReal on a given start address

Parameters:
length - the length byte
Returns:
the NSReal
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseDate

protected NSDate parseDate(byte length)
                    throws IOException
Parse a node to a NSDate on a given start address

Parameters:
length - the length byte
Returns:
the NSDate
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseData

protected NSData parseData(byte length)
                    throws IOException,
                           PropertyListException
Parse a node to a NSData on a given start address

Parameters:
length - the length byte
Returns:
the NSData
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseASCII

protected NSString parseASCII(byte length)
                       throws IOException,
                              PropertyListException
Parse a node to a NSString on a given start address, parsing with an ASCII charset

Parameters:
length - the length byte
Returns:
the NSString
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseUnicode

protected NSString parseUnicode(byte length)
                         throws IOException,
                                PropertyListException
Parse a node to a NSString on a given start address, parsing with an unicode charset

Parameters:
length - the length byte
Returns:
the NSString
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseUid

protected NSObject parseUid(byte length)
                     throws IOException,
                            PropertyListException
Parse a NSUID (not implemented)

Parameters:
length - the length byte
Returns:
null
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseArray

protected NSArray parseArray(byte length)
                      throws IOException,
                             PropertyListException
Parse a node to a NSArray on a given start address

Parameters:
length - the length byte
Returns:
the NSArray
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseSet

protected NSObject parseSet(byte length)
                     throws IOException,
                            PropertyListException
Parse a NSSet (not implemented)

Parameters:
length - the length byte
Returns:
null
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

parseDictionary

protected NSDictionary parseDictionary(byte length)
                                throws IOException,
                                       PropertyListException
Parse a node to a NSDictionary on a given start address

Parameters:
length - the length byte
Returns:
the NSDictionary
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails

getLength

protected int getLength(byte lengthMask)
                 throws IOException,
                        PropertyListException

Read the length

When the lengthMask is 0xF (0000 1111), an integer follows containing the actual length

lengthMask must be equal or smaller than LENMASK

Parameters:
lengthMask - the length mask
Returns:
the actual length (equal to lengthMask if lengthMask != 0xF)
Throws:
IOException - when reading the stream failed while parsing
PropertyListException - when parsing fails