Package com.dd.plist
Class BinaryPropertyListParser
- java.lang.Object
-
- com.dd.plist.BinaryPropertyListParser
-
public final class BinaryPropertyListParser extends java.lang.ObjectParses 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
parsemethods.
-
-
Field Summary
Fields Modifier and Type Field Description private static intARRAY_TYPEprivate static intASCII_STRING_TYPEprivate byte[]bytesThe property list data.private static intDATA_TYPEprivate static intDATE_TYPEprivate static intDICTIONARY_TYPEprivate static intINT_TYPEprivate intmajorVersionMajor version of the property list formatprivate intminorVersionMinor version of the property list formatprivate intnumObjectsprivate intobjectRefSizeLength of an object reference in bytesprivate intoffsetSizeprivate intoffsetTableOffsetprivate static intORDERED_SET_TYPEprivate java.util.HashMap<java.lang.Integer,NSObject>parsedObjectsprivate static intREAL_TYPEprivate static intSET_TYPEprivate static intSIMPLE_TYPEprivate static intUID_TYPEprivate static intUTF16_STRING_TYPEprivate static intUTF8_STRING_TYPE
-
Constructor Summary
Constructors Modifier Constructor Description privateBinaryPropertyListParser()Protected constructor so that instantiation is fully controlled by the static parse methods.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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 NSObjectparse(java.io.File f)Parses a binary property list file.static NSObjectparse(java.io.InputStream is)Parses a binary property list from an input stream.static NSObjectparse(java.nio.file.Path path)Parses 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, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> stringLengthCalculator, java.lang.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 Detail
-
SIMPLE_TYPE
private static final int SIMPLE_TYPE
- See Also:
- Constant Field Values
-
INT_TYPE
private static final int INT_TYPE
- See Also:
- Constant Field Values
-
REAL_TYPE
private static final int REAL_TYPE
- See Also:
- Constant Field Values
-
DATE_TYPE
private static final int DATE_TYPE
- See Also:
- Constant Field Values
-
DATA_TYPE
private static final int DATA_TYPE
- See Also:
- Constant Field Values
-
ASCII_STRING_TYPE
private static final int ASCII_STRING_TYPE
- See Also:
- Constant Field Values
-
UTF16_STRING_TYPE
private static final int UTF16_STRING_TYPE
- See Also:
- Constant Field Values
-
UTF8_STRING_TYPE
private static final int UTF8_STRING_TYPE
- See Also:
- Constant Field Values
-
UID_TYPE
private static final int UID_TYPE
- See Also:
- Constant Field Values
-
ARRAY_TYPE
private static final int ARRAY_TYPE
- See Also:
- Constant Field Values
-
ORDERED_SET_TYPE
private static final int ORDERED_SET_TYPE
- See Also:
- Constant Field Values
-
SET_TYPE
private static final int SET_TYPE
- See Also:
- Constant Field Values
-
DICTIONARY_TYPE
private static final int DICTIONARY_TYPE
- See Also:
- Constant Field Values
-
majorVersion
private int majorVersion
Major version of the property list format
-
minorVersion
private int minorVersion
Minor version of the property list format
-
bytes
private byte[] bytes
The property list data.
-
objectRefSize
private int objectRefSize
Length of an object reference in bytes
-
offsetSize
private int offsetSize
-
numObjects
private int numObjects
-
offsetTableOffset
private int offsetTableOffset
-
parsedObjects
private java.util.HashMap<java.lang.Integer,NSObject> parsedObjects
-
-
Constructor Detail
-
BinaryPropertyListParser
private BinaryPropertyListParser()
Protected constructor so that instantiation is fully controlled by the static parse methods.- See Also:
parse(byte[])
-
-
Method Detail
-
parse
public static NSObject parse(java.io.File f) throws java.io.IOException, PropertyListFormatException
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.java.io.IOException- If aNSStringobject could not be decoded or an I/O error occurs on the input stream.
-
parse
public static NSObject parse(java.nio.file.Path path) throws java.io.IOException, PropertyListFormatException
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.java.io.IOException- If aNSStringobject could not be decoded or an I/O error occurs on the input stream.
-
parse
public static NSObject parse(java.io.InputStream is) throws java.io.IOException, PropertyListFormatException
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.java.io.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, java.io.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.java.io.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, java.io.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.java.io.UnsupportedEncodingException- If aNSStringobject could not be decoded.
-
parseObject
private NSObject parseObject(ParsedObjectStack stack, int obj) throws PropertyListFormatException, java.io.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.java.io.UnsupportedEncodingException- If aNSStringobject could not be decoded.
-
parseDate
private NSDate parseDate(int offset, int objInfo) throws PropertyListFormatException
- Throws:
PropertyListFormatException
-
parseData
private NSData parseData(int offset, int objInfo) throws PropertyListFormatException
- Throws:
PropertyListFormatException
-
parseSimpleObject
private NSObject parseSimpleObject(int offset, int objInfo, int objType, int obj) throws PropertyListFormatException
- Throws:
PropertyListFormatException
-
parseUid
private UID parseUid(int obj, int offset, int length) throws PropertyListFormatException
- Throws:
PropertyListFormatException
-
parseNumber
private NSNumber parseNumber(int offset, int objInfo, int integer) throws PropertyListFormatException
- Throws:
PropertyListFormatException
-
parseString
private NSString parseString(int offset, int objInfo, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> stringLengthCalculator, java.lang.String charsetName) throws PropertyListFormatException, java.io.UnsupportedEncodingException
- Throws:
PropertyListFormatExceptionjava.io.UnsupportedEncodingException
-
parseArray
private NSArray parseArray(int offset, int objInfo, ParsedObjectStack stack) throws PropertyListFormatException, java.io.UnsupportedEncodingException
- Throws:
PropertyListFormatExceptionjava.io.UnsupportedEncodingException
-
parseSet
private NSSet parseSet(int offset, int objInfo, boolean ordered, ParsedObjectStack stack) throws PropertyListFormatException, java.io.UnsupportedEncodingException
- Throws:
PropertyListFormatExceptionjava.io.UnsupportedEncodingException
-
parseDictionary
private NSDictionary parseDictionary(int offset, int objInfo, ParsedObjectStack stack) throws PropertyListFormatException, java.io.UnsupportedEncodingException
- Throws:
PropertyListFormatExceptionjava.io.UnsupportedEncodingException
-
readLengthAndOffset
private int[] readLengthAndOffset(int objInfo, int offset) throws PropertyListFormatException- 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
private int parseObjectReference(int offset) throws PropertyListFormatException- Throws:
PropertyListFormatException
-
getObjectOffset
private int getObjectOffset(int obj) throws PropertyListFormatException- Throws:
PropertyListFormatException
-
-