Class BinaryPropertyListParser
java.lang.Object
com.dd.plist.BinaryPropertyListParser
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate byte[]The property list data.private static final intprivate static final intprivate static final intprivate static final intprivate intMajor version of the property list formatprivate intMinor version of the property list formatprivate intprivate intLength of an object reference in bytesprivate intprivate intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateProtected constructor so that instantiation is fully controlled by the static parse methods. -
Method Summary
Modifier and TypeMethodDescriptionprivate intcalculateUtf8StringLength(int offset, int numCharacters) static byte[]copyOfRange(byte[] src, int startIndex, int endIndex) Copies a part of a byte array into a new array.private NSObjectdoParse(byte[] data) Parses a binary property list from a byte array.private intgetObjectOffset(int obj) private booleanhastUtf8Sequence(int offset, int n) static NSObjectparse(byte[] data) Parses a binary property list from a byte array.static NSObjectParses a binary property list file.static NSObjectparse(InputStream is) Parses a binary property list from an input stream.static NSObjectParses a binary property list file.private NSArrayparseArray(int offset, int objInfo, ParsedObjectStack stack) private NSDataparseData(int offset, int objInfo) private NSDateparseDate(int offset, int objInfo) private NSDictionaryparseDictionary(int offset, int objInfo, ParsedObjectStack stack) static doubleparseDouble(byte[] bytes) Parses a double from a (big-endian) byte array.static doubleparseDouble(byte[] bytes, int startIndex, int endIndex) Parses a double from a (big-endian) byte array.static longparseLong(byte[] bytes) Parses a long from a (big-endian) byte array.static longparseLong(byte[] bytes, int startIndex, int endIndex) Parses a long from a (big-endian) byte array.private NSNumberparseNumber(int offset, int objInfo, int integer) private NSObjectparseObject(ParsedObjectStack stack, int obj) Parses an object inside the currently parsed binary property list.private intparseObjectReference(int offset) private intparseObjectReferenceFromList(int baseOffset, int objectIndex) private NSSetparseSet(int offset, int objInfo, boolean ordered, ParsedObjectStack stack) private NSObjectparseSimpleObject(int offset, int objInfo, int objType, int obj) private NSStringparseString(int offset, int objInfo, BiFunction<Integer, Integer, Integer> stringLengthCalculator, String charsetName) private UIDparseUid(int obj, int offset, int length) static longparseUnsignedInt(byte[] bytes) Parses an unsigned integers from a byte array.static longparseUnsignedInt(byte[] bytes, int startIndex, int endIndex) Parses an unsigned integer from a byte array.private int[]readLengthAndOffset(int objInfo, int offset)
-
Field Details
-
SIMPLE_TYPE
private static final int SIMPLE_TYPE- See Also:
-
INT_TYPE
private static final int INT_TYPE- See Also:
-
REAL_TYPE
private static final int REAL_TYPE- See Also:
-
DATE_TYPE
private static final int DATE_TYPE- See Also:
-
DATA_TYPE
private static final int DATA_TYPE- See Also:
-
ASCII_STRING_TYPE
private static final int ASCII_STRING_TYPE- See Also:
-
UTF16_STRING_TYPE
private static final int UTF16_STRING_TYPE- See Also:
-
UTF8_STRING_TYPE
private static final int UTF8_STRING_TYPE- See Also:
-
UID_TYPE
private static final int UID_TYPE- See Also:
-
ARRAY_TYPE
private static final int ARRAY_TYPE- See Also:
-
ORDERED_SET_TYPE
private static final int ORDERED_SET_TYPE- See Also:
-
SET_TYPE
private static final int SET_TYPE- See Also:
-
DICTIONARY_TYPE
private static final int DICTIONARY_TYPE- See Also:
-
majorVersion
private int majorVersionMajor version of the property list format -
minorVersion
private int minorVersionMinor version of the property list format -
bytes
private byte[] bytesThe property list data. -
objectRefSize
private int objectRefSizeLength of an object reference in bytes -
offsetSize
private int offsetSize -
numObjects
private int numObjects -
offsetTableOffset
private int offsetTableOffset -
parsedObjects
-
-
Constructor Details
-
BinaryPropertyListParser
private BinaryPropertyListParser()Protected constructor so that instantiation is fully controlled by the static parse methods.- See Also:
-
-
Method Details
-
parse
Parses a binary property list file.- Parameters:
f- The binary property list file- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
PropertyListFormatException- When the property list's format could not be parsed.IOException- If aNSStringobject could not be decoded or an I/O error occurs on the input stream.
-
parse
Parses a binary property list file.- Parameters:
path- The path to the binary property list file- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
PropertyListFormatException- When the property list's format could not be parsed.IOException- If aNSStringobject could not be decoded or an I/O error occurs on the input stream.
-
parse
Parses a binary property list from an input stream. This method does not close the specified input stream.- Parameters:
is- The input stream that points to the property list's data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
PropertyListFormatException- When the property list's format could not be parsed.IOException- If aNSStringobject could not be decoded or an I/O error occurs on the input stream.
-
parse
public static NSObject parse(byte[] data) throws PropertyListFormatException, UnsupportedEncodingException Parses a binary property list from a byte array.- Parameters:
data- The binary property list's data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
PropertyListFormatException- When the property list's format could not be parsed.UnsupportedEncodingException- If aNSStringobject could not be decoded.
-
parseUnsignedInt
public static long parseUnsignedInt(byte[] bytes) Parses an unsigned integers from a byte array.- Parameters:
bytes- The byte array containing the unsigned integer.- Returns:
- The unsigned integer represented by the given bytes.
-
parseUnsignedInt
public static long parseUnsignedInt(byte[] bytes, int startIndex, int endIndex) Parses an unsigned integer from a byte array.- Parameters:
bytes- The byte array containing the unsigned integer.startIndex- Beginning of the unsigned int in the byte array.endIndex- End of the unsigned int in the byte array.- Returns:
- The unsigned integer represented by the given bytes.
-
parseLong
public static long parseLong(byte[] bytes) Parses a long from a (big-endian) byte array.- Parameters:
bytes- The bytes representing the long integer.- Returns:
- The long integer represented by the given bytes.
-
parseLong
public static long parseLong(byte[] bytes, int startIndex, int endIndex) Parses a long from a (big-endian) byte array.- Parameters:
bytes- The bytes representing the long integer.startIndex- Beginning of the long in the byte array.endIndex- End of the long in the byte array.- Returns:
- The long integer represented by the given bytes.
-
parseDouble
public static double parseDouble(byte[] bytes) Parses a double from a (big-endian) byte array.- Parameters:
bytes- The bytes representing the double.- Returns:
- The double represented by the given bytes.
-
parseDouble
public static double parseDouble(byte[] bytes, int startIndex, int endIndex) Parses a double from a (big-endian) byte array.- Parameters:
bytes- The bytes representing the double.startIndex- Beginning of the double in the byte array.endIndex- End of the double in the byte array.- Returns:
- The double represented by the given bytes.
-
copyOfRange
public static byte[] copyOfRange(byte[] src, int startIndex, int endIndex) Copies a part of a byte array into a new array.- Parameters:
src- The source array.startIndex- The index from which to start copying.endIndex- The index until which to copy.- Returns:
- The copied array.
-
doParse
private NSObject doParse(byte[] data) throws PropertyListFormatException, UnsupportedEncodingException Parses a binary property list from a byte array.- Parameters:
data- The binary property list's data.- Returns:
- The root object of the property list. This is usually a
NSDictionarybut can also be aNSArray. - Throws:
PropertyListFormatException- When the property list's format could not be parsed.UnsupportedEncodingException- If aNSStringobject could not be decoded.
-
parseObject
private NSObject parseObject(ParsedObjectStack stack, int obj) throws PropertyListFormatException, UnsupportedEncodingException Parses an object inside the currently parsed binary property list. For the format specification check Apple's binary property list parser implementation.- Parameters:
stack- The stack to keep track of parsed objects and detect cyclic references.obj- The object ID.- Returns:
- The parsed object.
- Throws:
PropertyListFormatException- When the property list's format could not be parsed.UnsupportedEncodingException- If aNSStringobject could not be decoded.
-
parseDate
- Throws:
PropertyListFormatException
-
parseData
- Throws:
PropertyListFormatException
-
parseSimpleObject
private NSObject parseSimpleObject(int offset, int objInfo, int objType, int obj) throws PropertyListFormatException - Throws:
PropertyListFormatException
-
parseUid
- Throws:
PropertyListFormatException
-
parseNumber
private NSNumber parseNumber(int offset, int objInfo, int integer) throws PropertyListFormatException - Throws:
PropertyListFormatException
-
parseString
private NSString parseString(int offset, int objInfo, BiFunction<Integer, Integer, throws PropertyListFormatException, UnsupportedEncodingExceptionInteger> stringLengthCalculator, String charsetName) -
parseArray
private NSArray parseArray(int offset, int objInfo, ParsedObjectStack stack) throws PropertyListFormatException, UnsupportedEncodingException -
parseSet
private NSSet parseSet(int offset, int objInfo, boolean ordered, ParsedObjectStack stack) throws PropertyListFormatException, UnsupportedEncodingException -
parseDictionary
private NSDictionary parseDictionary(int offset, int objInfo, ParsedObjectStack stack) throws PropertyListFormatException, UnsupportedEncodingException -
readLengthAndOffset
- Throws:
PropertyListFormatException
-
calculateUtf8StringLength
private int calculateUtf8StringLength(int offset, int numCharacters) -
hastUtf8Sequence
private boolean hastUtf8Sequence(int offset, int n) -
parseObjectReferenceFromList
private int parseObjectReferenceFromList(int baseOffset, int objectIndex) throws PropertyListFormatException - Throws:
PropertyListFormatException
-
parseObjectReference
- Throws:
PropertyListFormatException
-
getObjectOffset
- Throws:
PropertyListFormatException
-