Package com.dd.plist

Class BinaryPropertyListParser


  • public final class BinaryPropertyListParser
    extends java.lang.Object
    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 Detail

      • 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 NSDictionary but can also be a NSArray.
        Throws:
        PropertyListFormatException - When the property list's format could not be parsed.
        java.io.IOException - If a NSString object 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 NSDictionary but can also be a NSArray.
        Throws:
        PropertyListFormatException - When the property list's format could not be parsed.
        java.io.IOException - If a NSString object 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 NSDictionary but can also be a NSArray.
        Throws:
        PropertyListFormatException - When the property list's format could not be parsed.
        java.io.IOException - If a NSString object 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 NSDictionary but can also be a NSArray.
        Throws:
        PropertyListFormatException - When the property list's format could not be parsed.
        java.io.UnsupportedEncodingException - If a NSString object 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 NSDictionary but can also be a NSArray.
        Throws:
        PropertyListFormatException - When the property list's format could not be parsed.
        java.io.UnsupportedEncodingException - If a NSString object could not be decoded.
      • 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:
        PropertyListFormatException
        java.io.UnsupportedEncodingException
      • calculateUtf8StringLength

        private int calculateUtf8StringLength​(int offset,
                                              int numCharacters)
      • hastUtf8Sequence

        private boolean hastUtf8Sequence​(int offset,
                                         int n)