Package com.dd.plist

Class PropertyListParser


  • public class PropertyListParser
    extends java.lang.Object
    Parses property lists. The parser can handle files, input streams and byte arrays. All known property list formats are supported.
    • Constructor Detail

      • PropertyListParser

        protected PropertyListParser()
        Prevent instantiation.
    • Method Detail

      • determineType

        private static int determineType​(java.lang.String dataBeginning)
        Determines the property list type by means of the first bytes of its data.
        Parameters:
        dataBeginning - The very first bytes of data of the property list (minus any whitespace) as a string.
        Returns:
        The type of the property list.
      • determineType

        private static int determineType​(java.io.InputStream is,
                                         int offset)
                                  throws java.io.IOException
        Determines the property list type by means of the first bytes of its data.
        Parameters:
        is - An input stream pointing to the beginning of the property list data. If the stream supports marking it will be reset to the beginning of the property list data after the type has been determined.
        offset - The number of bytes to skip in the stream.
        Returns:
        The type of the property list.
        Throws:
        java.io.IOException
      • readAll

        protected static byte[] readAll​(java.io.InputStream in)
                                 throws java.io.IOException
        Reads all bytes from an InputStream and stores them in an array, up to a maximum count.
        Parameters:
        in - The InputStream pointing to the data that should be stored in the array.
        Returns:
        An array containing all bytes that were read from the input stream.
        Throws:
        java.io.IOException - If an I/O error occurs while reading from the input stream.
      • parse

        public static NSObject parse​(java.lang.String filePath)
                              throws javax.xml.parsers.ParserConfigurationException,
                                     java.text.ParseException,
                                     org.xml.sax.SAXException,
                                     PropertyListFormatException,
                                     java.io.IOException
        Parses a property list from a file.
        Parameters:
        filePath - The path to the property list file.
        Returns:
        The root object in the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If the given property list has an invalid format.
      • parse

        public static NSObject parse​(java.io.File f)
                              throws java.io.IOException,
                                     PropertyListFormatException,
                                     java.text.ParseException,
                                     javax.xml.parsers.ParserConfigurationException,
                                     org.xml.sax.SAXException
        Parses a property list from a file.
        Parameters:
        f - The property list file.
        Returns:
        The root object in the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If the given property list has an invalid format.
      • parse

        public static NSObject parse​(java.nio.file.Path path)
                              throws java.io.IOException,
                                     PropertyListFormatException,
                                     java.text.ParseException,
                                     javax.xml.parsers.ParserConfigurationException,
                                     org.xml.sax.SAXException
        Parses a property list from a file.
        Parameters:
        path - The path to the property list file.
        Returns:
        The root object in the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If the given property list has an invalid format.
      • parse

        public static NSObject parse​(byte[] bytes)
                              throws java.io.IOException,
                                     PropertyListFormatException,
                                     java.text.ParseException,
                                     javax.xml.parsers.ParserConfigurationException,
                                     org.xml.sax.SAXException
        Parses a property list from a byte array.
        Parameters:
        bytes - The property list data as a byte array.
        Returns:
        The root object in the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the byte array.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If the given property list has an invalid format.
      • parse

        public static NSObject parse​(java.io.InputStream is)
                              throws java.io.IOException,
                                     PropertyListFormatException,
                                     java.text.ParseException,
                                     javax.xml.parsers.ParserConfigurationException,
                                     org.xml.sax.SAXException
        Parses a property list from an InputStream. This method does not close the specified input stream.
        Parameters:
        is - The InputStream delivering the property list data.
        Returns:
        The root object of the property list. This is usually a NSDictionary but can also be a NSArray.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the input stream.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If the given property list has an invalid format.
      • saveAsXML

        @Deprecated
        public static void saveAsXML​(NSObject root,
                                     java.io.File out)
                              throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root into an XML file.
        Parameters:
        root - The root object.
        out - The output file. If the output file's parent directory does not exist, it will be created.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • saveAsXML

        @Deprecated
        public static void saveAsXML​(NSObject root,
                                     java.io.OutputStream out)
                              throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root in XML format into an output stream. This method does not close the specified output stream.
        Parameters:
        root - The root object.
        out - The output stream.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • convertToXml

        @Deprecated
        public static void convertToXml​(java.io.File in,
                                        java.io.File out)
                                 throws javax.xml.parsers.ParserConfigurationException,
                                        java.text.ParseException,
                                        org.xml.sax.SAXException,
                                        PropertyListFormatException,
                                        java.io.IOException
        Deprecated.
        Converts a given property list file into the OS X and iOS XML format.
        Parameters:
        in - The source file.
        out - The target file. If the output file's parent directory does not exist, it will be created.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing an XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the input file or writing the output file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a date string could not be parsed.
      • saveAsBinary

        public static void saveAsBinary​(NSObject root,
                                        java.io.File out)
                                 throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root into a binary file.
        Parameters:
        root - The root object.
        out - The output file. If the output file's parent directory does not exist, it will be created.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • saveAsBinary

        @Deprecated
        public static void saveAsBinary​(NSObject root,
                                        java.io.OutputStream out)
                                 throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root in binary format into an output stream. This method does not close the specified input stream.
        Parameters:
        root - The root object.
        out - The output stream.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • convertToBinary

        @Deprecated
        public static void convertToBinary​(java.io.File in,
                                           java.io.File out)
                                    throws java.io.IOException,
                                           javax.xml.parsers.ParserConfigurationException,
                                           java.text.ParseException,
                                           org.xml.sax.SAXException,
                                           PropertyListFormatException
        Deprecated.
        Converts a given property list file into the OS X and iOS binary format.
        Parameters:
        in - The source file.
        out - The target file. If the output file's parent directory does not exist, it will be created.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing a XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the input file or writing the output file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a date string could not be parsed.
      • saveAsASCII

        @Deprecated
        public static void saveAsASCII​(NSDictionary root,
                                       java.io.File out)
                                throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root into an ASCII file.
        Parameters:
        root - The root object.
        out - The output file. If the output file's parent directory does not exist, it will be created.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • saveAsASCII

        @Deprecated
        public static void saveAsASCII​(NSArray root,
                                       java.io.File out)
                                throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root into an ASCII file.
        Parameters:
        root - The root object.
        out - The output file. If the output file's parent directory does not exist, it will be created.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • convertToASCII

        @Deprecated
        public static void convertToASCII​(java.io.File in,
                                          java.io.File out)
                                   throws javax.xml.parsers.ParserConfigurationException,
                                          java.text.ParseException,
                                          org.xml.sax.SAXException,
                                          PropertyListFormatException,
                                          java.io.IOException
        Deprecated.
        Converts a given property list file into ASCII format.
        Parameters:
        in - The source file.
        out - The target file. If the file's parent directory does not exist, it will be created.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing a XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the input file or writing the output file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a date string could not be parsed.
      • saveAsGnuStepASCII

        @Deprecated
        public static void saveAsGnuStepASCII​(NSDictionary root,
                                              java.io.File out)
                                       throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root into an ASCII file.
        Parameters:
        root - The root object.
        out - The output file. If the output file's parent directory does not exist, it will be created.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • saveAsGnuStepASCII

        @Deprecated
        public static void saveAsGnuStepASCII​(NSArray root,
                                              java.io.File out)
                                       throws java.io.IOException
        Deprecated.
        Saves a property list with the given object as root into an ASCII file.
        Parameters:
        root - The root object.
        out - The output file. If the output file's parent directory does not exist, it will be created.
        Throws:
        java.io.IOException - If an error occurs during the writing process.
      • convertToGnuStepASCII

        @Deprecated
        public static void convertToGnuStepASCII​(java.io.File in,
                                                 java.io.File out)
                                          throws javax.xml.parsers.ParserConfigurationException,
                                                 java.text.ParseException,
                                                 org.xml.sax.SAXException,
                                                 PropertyListFormatException,
                                                 java.io.IOException
        Deprecated.
        Converts a given property list file into ASCII format.
        Parameters:
        in - The source file.
        out - The target file.
        Throws:
        javax.xml.parsers.ParserConfigurationException - If a document builder for parsing a XML property list could not be created. This should not occur.
        java.io.IOException - If any I/O error occurs while reading the input file or writing the output file.
        org.xml.sax.SAXException - If any parse error occurs.
        PropertyListFormatException - If the given property list has an invalid format.
        java.text.ParseException - If a date string could not be parsed.