/** * Parses a binary property list from an input stream. * This method does not close the specified input stream. * * @param is The input stream that points to the property list's data. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @throws PropertyListFormatException When the property list's format could not be parsed. * @throws java.io.IOException If a {@link NSString} object could not be decoded or an I/O error occurs on the input stream. */ public static NSObject parse(InputStream is) throws IOException, PropertyListFormatException { return parse(PropertyListParser.readAll(is)); }
/** * Puts a new key-value pair into this dictionary. * If key or value are null, no operation will be performed on the dictionary. * * @param key The key. * @param obj The value. Supported object types are numbers, byte-arrays, dates, strings and arrays or sets of those. * @return The value previously associated to the given key, * or null, if no value was associated to it. */ public NSObject put(String key, Object obj) { return this.put(key, NSObject.fromJavaObject(obj)); }
private Object[] deserializeArray() { NSObject[] originalArray = ((NSArray)this).getArray(); Object[] clonedArray = new Object[originalArray.length]; for(int i = 0; i < originalArray.length; i++) { clonedArray[i] = originalArray[i].toJavaObject(); } return clonedArray; }
private static NSSet fromSet(Set<?> set) { NSSet result = new NSSet(); for (Object elem : set) { result.addObject(fromJavaObject(elem)); } return result; }
@Override void toBinary(BinaryPropertyListWriter out) throws IOException { out.writeIntHeader(0xA, this.array.length); for(NSObject obj : this.array) { out.writeID(out.getID(obj)); } }
/** * Prepends a string to this string. * * @param s The string to prepend. */ public void prepend(NSString s) { this.prepend(s.getContent()); }
@Override void toBinary(BinaryPropertyListWriter out) throws IOException { out.writeIntHeader(0x4, this.bytes.length); out.write(this.bytes); }
void writeBytes(long value, int bytes) throws IOException { // write low-order bytes big-endian style for (int i = bytes - 1; i >= 0; i--) { this.write((int) (value >> (8 * i))); } }
/** * Parses an ASCII property list from an input stream. * This method does not close the specified input stream. * * @param in The input stream that points to the property list's data. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @throws java.text.ParseException If an error occurs during parsing. * @throws java.io.IOException If an error occurs while reading from the input stream. */ public static NSObject parse(InputStream in) throws ParseException, IOException { return parse(PropertyListParser.readAll(in)); }
/** * Parses a binary property list from a byte array. * * @param data The binary property list's data. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @throws PropertyListFormatException When the property list's format could not be parsed. * @throws java.io.UnsupportedEncodingException If a {@link NSString} object could not be decoded. */ public static NSObject parse(byte[] data) throws PropertyListFormatException, UnsupportedEncodingException { BinaryPropertyListParser parser = new BinaryPropertyListParser(); return parser.doParse(data); }
/** * Gets the Base64 encoded data contained in this instance. * * @return The data as a Base64 encoded <code>String</code>. */ public String getBase64EncodedData() { return Base64.encodeBytes(this.bytes); }
/** * Parses an unsigned integers from a byte array. * * @param bytes The byte array containing the unsigned integer. * @return The unsigned integer represented by the given bytes. */ @SuppressWarnings("unused") public static long parseUnsignedInt(byte[] bytes) { return parseUnsignedInt(bytes, 0, bytes.length); }
/** * Parses a long from a (big-endian) byte array. * * @param bytes The bytes representing the long integer. * @return The long integer represented by the given bytes. */ @SuppressWarnings("unused") public static long parseLong(byte[] bytes) { return parseLong(bytes, 0, bytes.length); }
@Override protected void toASCIIGnuStep(StringBuilder ascii, int level) { this.toASCII(ascii, level); } }
/** * 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. * * @param root The root object. * @param out The output stream. * @throws IOException If an error occurs during the writing process. */ public static void saveAsBinary(NSObject root, OutputStream out) throws IOException { BinaryPropertyListWriter.write(out, root); }
/** * Parses an ASCII property list from an input stream. * This method does not close the specified input stream. * * @param in The input stream that points to the property list's data. * @param encoding The name of a supported {@link java.nio.charset.Charset charset} to decode the property list. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @throws java.text.ParseException If an error occurs during parsing. * @throws java.io.IOException If an error occurs while reading from the input stream. * @throws java.io.UnsupportedEncodingException If no support for the named charset is available in this instance of the Java virtual machine. */ public static NSObject parse(InputStream in, String encoding) throws ParseException, IOException { return parse(PropertyListParser.readAll(in), encoding); }