Top Description Fields Constructors Methods
com.dd.plist

public final Class BinaryPropertyListParser

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, .UnsupportedEncodingException, java.math.BigInteger, java.nio.charset.StandardCharsets, java.nio.file.Files, .Path, java.util.HashMap, .HashSet, .Objects, java.util.function.BiFunction

Parses property lists that are in Apple's binary format. Use this class when you are sure about the format of the property list. Otherwise, use the PropertyListParser class.

Parsing is done by calling the static parse methods.

Author
Daniel Dreibrodt

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private byte[]
bytes

The property list data.

private static final int
private static final int
private static final int
private static final int
private int
majorVersion

Major version of the property list format

private int
minorVersion

Minor version of the property list format

private int
private int
objectRefSize

Length of an object reference in bytes

private int
private int
private static final int
private final HashMap<Integer, NSObject>
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private
BinaryPropertyListParser()

Protected constructor so that instantiation is fully controlled by the static parse methods.

Method Summary

Modifier and TypeMethod and Description
private static String
buildLengthError(int offset, String objectType)

private String
buildTypeError(int offset)

private String
buildTypeError(int offset, String objectType)

private int
calculateUtf8StringLength(int offset, int numCharacters)

public static byte[]

Returns:

The copied array.
copyOfRange
(byte[]
The source array.
src
,
int
The index from which to start copying.
startIndex
,
int
The index until which to copy.
endIndex
)

Copies a part of a byte array into a new array.

private NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
doParse
(byte[]
The binary property list's data.
data
)

Parses a binary property list from a byte array.

private int
getObjectOffset(int obj)

private boolean
hastUtf8Sequence(int offset, int n)

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(File
The binary property list file
f
)

Parses a binary property list file.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(Path
The path to the binary property list file
path
)

Parses a binary property list file.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(InputStream
The input stream that points to the property list's data.
is
)

Parses a binary property list from an input stream.

public static NSObject

Returns:

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
parse
(byte[]
The binary property list's data.
data
)

Parses a binary property list from a byte array.

private NSArray
parseArray(int offset, int objInfo, ParsedObjectStack stack)

private NSData
parseData(int offset, int objInfo)

private NSDate
parseDate(int offset, int objInfo)

private NSDictionary
parseDictionary(int offset, int objInfo, ParsedObjectStack stack)

public static double

Returns:

The double represented by the given bytes.
parseDouble
(byte[]
The bytes representing the double.
bytes
)

Parses a double from a (big-endian) byte array.

public static double

Returns:

The double represented by the given bytes.
parseDouble
(byte[]
The bytes representing the double.
bytes
,
int
Beginning of the double in the byte array.
startIndex
,
int
End of the double in the byte array.
endIndex
)

Parses a double from a (big-endian) byte array.

public static long

Returns:

The long integer represented by the given bytes.
parseLong
(byte[]
The bytes representing the long integer.
bytes
)

Parses a long from a (big-endian) byte array.

public static long

Returns:

The long integer represented by the given bytes.
parseLong
(byte[]
The bytes representing the long integer.
bytes
,
int
Beginning of the long in the byte array.
startIndex
,
int
End of the long in the byte array.
endIndex
)

Parses a long from a (big-endian) byte array.

private NSNumber
parseNumber(int offset, int objInfo, int integer)

private NSObject

Returns:

The parsed object.
parseObject
(ParsedObjectStack
The stack to keep track of parsed objects and detect cyclic references.
stack
,
int
The object ID.
obj
)

Parses an object inside the currently parsed binary property list.

private int
private int
parseObjectReferenceFromList(int baseOffset, int objectIndex)

private NSSet
parseSet(int offset, int objInfo, boolean ordered, ParsedObjectStack stack)

private NSObject
parseSimpleObject(int offset, int objInfo, int obj)

private NSString
parseString(int offset, int objInfo, BiFunction<Integer, Integer, Integer> stringLengthCalculator, String charsetName)

private UID
parseUid(int obj, int offset, int length)

public static long

Returns:

The unsigned integer represented by the given bytes.
parseUnsignedInt
(byte[]
The byte array containing the unsigned integer.
bytes
)

Parses an unsigned integers from a byte array.

public static long

Returns:

The unsigned integer represented by the given bytes.
parseUnsignedInt
(byte[]
The byte array containing the unsigned integer.
bytes
,
int
Beginning of the unsigned int in the byte array.
startIndex
,
int
End of the unsigned int in the byte array.
endIndex
)

Parses an unsigned integer from a byte array.

private int[]
readLengthAndOffset(int objInfo, int offset)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARRAY_TYPEback to summary
private static final int ARRAY_TYPE
ASCII_STRING_TYPEback to summary
private static final int ASCII_STRING_TYPE
bytesback to summary
private byte[] bytes

The property list data.

DATA_TYPEback to summary
private static final int DATA_TYPE
DATE_TYPEback to summary
private static final int DATE_TYPE
DICTIONARY_TYPEback to summary
private static final int DICTIONARY_TYPE
INT_TYPEback to summary
private static final int INT_TYPE
majorVersionback to summary
private int majorVersion

Major version of the property list format

Annotations
@SuppressWarnings:FieldCanBeLocal
minorVersionback to summary
private int minorVersion

Minor version of the property list format

Annotations
@SuppressWarnings:FieldCanBeLocal
numObjectsback to summary
private int numObjects
objectRefSizeback to summary
private int objectRefSize

Length of an object reference in bytes

offsetSizeback to summary
private int offsetSize
offsetTableOffsetback to summary
private int offsetTableOffset
ORDERED_SET_TYPEback to summary
private static final int ORDERED_SET_TYPE
parsedObjectsback to summary
private final HashMap<Integer, NSObject> parsedObjects
REAL_TYPEback to summary
private static final int REAL_TYPE
SET_TYPEback to summary
private static final int SET_TYPE
SIMPLE_TYPEback to summary
private static final int SIMPLE_TYPE
UID_TYPEback to summary
private static final int UID_TYPE
UTF16_STRING_TYPEback to summary
private static final int UTF16_STRING_TYPE
UTF8_STRING_TYPEback to summary
private static final int UTF8_STRING_TYPE

Constructor Detail

BinaryPropertyListParserback to summary
private BinaryPropertyListParser()

Protected constructor so that instantiation is fully controlled by the static parse methods.

See Also
BinaryPropertyListParser#parse(byte[])

Method Detail

buildLengthErrorback to summary
private static String buildLengthError(int offset, String objectType)
buildTypeErrorback to summary
private String buildTypeError(int offset)
buildTypeErrorback to summary
private String buildTypeError(int offset, String objectType)
calculateUtf8StringLengthback to summary
private int calculateUtf8StringLength(int offset, int numCharacters)
copyOfRangeback to summary
public static byte[] copyOfRange(byte[] src, int startIndex, int endIndex)

Copies a part of a byte array into a new array.

Parameters
src:byte[]

The source array.

startIndex:int

The index from which to start copying.

endIndex:int

The index until which to copy.

Returns:byte[]

The copied array.

doParseback to summary
private NSObject doParse(byte[] data) throws PropertyListFormatException

Parses a binary property list from a byte array.

Parameters
data:byte[]

The binary property list's data.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
PropertyListFormatException:
When the property list's format could not be parsed.
getObjectOffsetback to summary
private int getObjectOffset(int obj) throws PropertyListFormatException
hastUtf8Sequenceback to summary
private boolean hastUtf8Sequence(int offset, int n)
parseback to summary
public static NSObject parse(File f) throws IOException, PropertyListFormatException

Parses a binary property list file.

Parameters
f:File

The binary property list file

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
IOException:
If a NSString object could not be decoded or an I/O error occurs on the input stream.
PropertyListFormatException:
When the property list's format could not be parsed.
parseback to summary
public static NSObject parse(Path path) throws IOException, PropertyListFormatException

Parses a binary property list file.

Parameters
path:Path

The path to the binary property list file

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
IOException:
If a NSString object could not be decoded or an I/O error occurs on the input stream.
PropertyListFormatException:
When the property list's format could not be parsed.
parseback to summary
public static NSObject parse(InputStream is) throws IOException, PropertyListFormatException

Parses a binary property list from an input stream. This method does not close the specified input stream.

Parameters
is:InputStream

The input stream that points to the property list's data.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
IOException:
If a NSString object could not be decoded or an I/O error occurs on the input stream.
PropertyListFormatException:
When the property list's format could not be parsed.
parseback to summary
public static NSObject parse(byte[] data) throws PropertyListFormatException, UnsupportedEncodingException

Parses a binary property list from a byte array.

Parameters
data:byte[]

The binary property list's data.

Returns:NSObject

The root object of the property list. This is usually a NSDictionary but can also be a NSArray.

Exceptions
PropertyListFormatException:
When the property list's format could not be parsed.
UnsupportedEncodingException:
If a NSString object could not be decoded.
parseArrayback to summary
private NSArray parseArray(int offset, int objInfo, ParsedObjectStack stack) throws PropertyListFormatException, UnsupportedEncodingException
parseDataback to summary
private NSData parseData(int offset, int objInfo) throws PropertyListFormatException
parseDateback to summary
private NSDate parseDate(int offset, int objInfo) throws PropertyListFormatException
parseDictionaryback to summary
private NSDictionary parseDictionary(int offset, int objInfo, ParsedObjectStack stack) throws PropertyListFormatException, UnsupportedEncodingException
parseDoubleback to summary
public static double parseDouble(byte[] bytes)

Parses a double from a (big-endian) byte array.

Parameters
bytes:byte[]

The bytes representing the double.

Returns:double

The double represented by the given bytes.

Annotations
@SuppressWarnings:unused
parseDoubleback to summary
public static double parseDouble(byte[] bytes, int startIndex, int endIndex)

Parses a double from a (big-endian) byte array.

Parameters
bytes:byte[]

The bytes representing the double.

startIndex:int

Beginning of the double in the byte array.

endIndex:int

End of the double in the byte array.

Returns:double

The double represented by the given bytes.

parseLongback to summary
public static long parseLong(byte[] bytes)

Parses a long from a (big-endian) byte array.

Parameters
bytes:byte[]

The bytes representing the long integer.

Returns:long

The long integer represented by the given bytes.

Annotations
@SuppressWarnings:unused
parseLongback to summary
public static long parseLong(byte[] bytes, int startIndex, int endIndex)

Parses a long from a (big-endian) byte array.

Parameters
bytes:byte[]

The bytes representing the long integer.

startIndex:int

Beginning of the long in the byte array.

endIndex:int

End of the long in the byte array.

Returns:long

The long integer represented by the given bytes.

parseNumberback to summary
private NSNumber parseNumber(int offset, int objInfo, int integer) throws PropertyListFormatException
parseObjectback to summary
private NSObject parseObject(ParsedObjectStack stack, int obj) throws PropertyListFormatException

Parses an object inside the currently parsed binary property list. For the format specification check Apple's binary property list parser implementation.

Parameters
stack:ParsedObjectStack

The stack to keep track of parsed objects and detect cyclic references.

obj:int

The object ID.

Returns:NSObject

The parsed object.

Exceptions
PropertyListFormatException:
When the property list's format could not be parsed.
parseObjectReferenceback to summary
private int parseObjectReference(int offset) throws PropertyListFormatException
parseObjectReferenceFromListback to summary
private int parseObjectReferenceFromList(int baseOffset, int objectIndex) throws PropertyListFormatException
parseSetback to summary
private NSSet parseSet(int offset, int objInfo, boolean ordered, ParsedObjectStack stack) throws PropertyListFormatException, UnsupportedEncodingException
parseSimpleObjectback to summary
private NSObject parseSimpleObject(int offset, int objInfo, int obj) throws PropertyListFormatException
parseStringback to summary
private NSString parseString(int offset, int objInfo, BiFunction<Integer, Integer, Integer> stringLengthCalculator, String charsetName) throws PropertyListFormatException, UnsupportedEncodingException
parseUidback to summary
private UID parseUid(int obj, int offset, int length) throws PropertyListFormatException
parseUnsignedIntback to summary
public static long parseUnsignedInt(byte[] bytes)

Parses an unsigned integers from a byte array.

Parameters
bytes:byte[]

The byte array containing the unsigned integer.

Returns:long

The unsigned integer represented by the given bytes.

Annotations
@SuppressWarnings:unused
parseUnsignedIntback to summary
public static long parseUnsignedInt(byte[] bytes, int startIndex, int endIndex)

Parses an unsigned integer from a byte array.

Parameters
bytes:byte[]

The byte array containing the unsigned integer.

startIndex:int

Beginning of the unsigned int in the byte array.

endIndex:int

End of the unsigned int in the byte array.

Returns:long

The unsigned integer represented by the given bytes.

readLengthAndOffsetback to summary
private int[] readLengthAndOffset(int objInfo, int offset) throws PropertyListFormatException