/** * Parses a property list from an InputStream. It can either be in XML or binary format. * * @param is The InputStream delivering the property list data * @return The root object of the property list * @throws Exception If an error occurred while parsing. */ public static NSObject parse(InputStream is) throws Exception { if (is.markSupported()) { is.mark(10); byte[] magic = new byte[8]; is.read(magic); is.reset(); String magic_string = new String(magic); if (magic_string.startsWith("bplist00")) { return BinaryPropertyListParser.parse(is); } else if (magic_string.startsWith("<?xml")) { return XMLPropertyListParser.parse(is); } else { throw new UnsupportedOperationException( "The given data is neither a binary nor a XML property list. ASCII property lists are not supported."); } } else { if (is.available() > Runtime.getRuntime().freeMemory()) { throw new Exception( "To little heap space available! Wanted to read " + is.available() + " bytes, but only " + Runtime.getRuntime().freeMemory() + " are available."); } byte[] buf = new byte[is.available()]; is.read(buf); is.close(); return parse(buf); } }
/** * Parses a property list from a byte array. It can either be in XML or binary format. * * @param bytes The property list data * @return The root object in the property list * @throws Exception If an error occurred while parsing. */ public static NSObject parse(byte[] bytes) throws Exception { byte[] magic = Arrays.copyOf(bytes, 8); String magic_string = new String(magic); if (magic_string.startsWith("bplist00")) { return BinaryPropertyListParser.parse(bytes); } else if (magic_string.startsWith("<?xml")) { return XMLPropertyListParser.parse(bytes); } else { throw new UnsupportedOperationException( "The given data is neither a binary nor a XML property list. ASCII property lists are not supported."); } }
/** * Parses a property list from a file. It can either be in XML or binary format. * * @param f The property list file * @return The root object in the property list * @throws Exception If an error occurred while parsing */ public static NSObject parse(File f) throws Exception { FileInputStream fis = new FileInputStream(f); byte[] magic = new byte[8]; fis.read(magic); String magic_string = new String(magic); fis.close(); if (magic_string.startsWith("bplist00")) { return BinaryPropertyListParser.parse(f); } else if (magic_string.startsWith("<?xml")) { return XMLPropertyListParser.parse(f); } else { throw new UnsupportedOperationException( "The given file is neither a binary nor a XML property list. ASCII property lists are not supported."); } }