Package com.webobjects.foundation

Examples of com.webobjects.foundation.NSMutableData


      }

      String string = jso.getString("bytes");
      NSData data = (NSData) NSPropertyListSerialization.propertyListFromString(string);
      if (NSMutableData.class.equals(clazz)) {
        NSMutableData mutableData = new NSMutableData(data);
        state.setSerialized(o, mutableData);
        return mutableData;
      }
      else if (NSData.class.equals(clazz)) {
        state.setSerialized(o, data);
View Full Code Here


        // } else {
        // // return raw string
        // aobj[0] = theString;
        // }
      } else if (ac[aBufferIndex] == '<') {
        NSMutableData data = new NSMutableData(_lengthOfData(ac, aBufferIndex));
        aBufferIndex = _readDataContentsIntoData(ac, aBufferIndex, data);
        aobj[0] = data;
      } else if (ac[aBufferIndex] == '[') {
        NSMutableArray<Object> array = new NSMutableArray<Object>();
        aBufferIndex = _readArrayContentsIntoArray(ac, aBufferIndex, array);
View Full Code Here

      else if (ac[aBufferIndex] == '"') {
        StringBuffer buffer = new StringBuffer(64);
        aBufferIndex = _readQuotedStringIntoStringBuffer(ac, aBufferIndex, buffer);
        aobj[0] = buffer.toString();
      } else if (ac[aBufferIndex] == '<') {
        NSMutableData data = new NSMutableData(_lengthOfData(ac, aBufferIndex));
        aBufferIndex = _readDataContentsIntoData(ac, aBufferIndex, data);
        aobj[0] = data;
      } else if (ac[aBufferIndex] == '(') {
        NSMutableArray<Object> array = new NSMutableArray<Object>();
        aBufferIndex = _readArrayContentsIntoArray(ac, aBufferIndex, array);
View Full Code Here

        long fileLength = 0;
        NSMutableData data;
        boolean dirty = false;
       
        public EOFIndexOutput(NSData contentData) {
            data = new NSMutableData(contentData);
            fileLength = data.length();
        }
View Full Code Here

      if (plist == null || out == null) {
        logger.warn("Encountered empty plist or null outputstream, returning");
        return;
      }

      NSMutableData theData = new NSMutableData();

      // write header
      theData.appendBytes("bplist00".getBytes());

      // add six padded bytes

      // do uniquing

      // flatten plist into object table
      List<EncodedObject> objectList = new ArrayList<EncodedObject>(512);
      Map<Object, Long> uniquingTable = new HashMap<Object, Long>(2048);
      long theTopObject = encodeObject(plist, objectList, uniquingTable);

      // determine ref size
      long numberOfObjects = objectList.size();
      int refsize = EncodedObject.refSizeForValue(numberOfObjects);

      List<Long> objectOffsets = new ArrayList<Long>(objectList.size());
      // write the byte
      for (EncodedObject object : objectList) {
        objectOffsets.add(Long.valueOf(theData.length()));
        object.appendToData(theData, refsize);
      }
      int offsetTableStart = theData.length();
     
      // CF expects intsize to be calculated based on the offset table start position
      // and not on the offset of the last object.
      int intsize = EncodedObject.refSizeForValue(offsetTableStart);

      for (Long offset : objectOffsets) {
        theData.appendBytes(EncodedObject.encodeRef(offset, intsize));
      }

      // add trailer calculations to data
      // typedef struct {
      // uint8_t _unused[5];
      // uint8_t _sortVersion;
      // uint8_t _offsetIntSize;
      // uint8_t _objectRefSize;
      // uint64_t _numObjects;
      // uint64_t _topObject;
      // uint64_t _offsetTableOffset;
      // } CFBinaryPlistTrailer;
      theData.appendBytes(new byte[5]);
      theData.appendByte((byte) 0x0); // _sortVersion which AFIK is not being used in CF
      theData.appendByte((byte) intsize); // _offsetIntSize which byte size for all ints in file
      theData.appendByte((byte) refsize); // _objectRefSize which is total # of objects value in bytes
      theData.appendBytes(longToByteArray2(numberOfObjects, 8)); // _numObjects which is object count
      theData.appendBytes(longToByteArray2(theTopObject, 8)); // _topObject appears to be set to 0 in CF
      theData.appendBytes(longToByteArray2(offsetTableStart, 8)); // _offsetTableOffset

      // write to stream
      try {
        theData.writeToStream(out);
      } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Failed to write binary property list ", e);
      }
    }
View Full Code Here

     * int 0001 nnnn ... // # of bytes is 2^nnnn, big-endian bytes
     *
     * @see offsetIntSize
     */
    private byte[] encodeCount(long value, Type marker) {
      NSMutableData data = new NSMutableData(16);
      if (value > IntegerMaxValue) {
        data.appendByte((byte) typeMarker(marker, 0x0f));
        data.appendByte((byte) typeMarker(Type.kCFBinaryPlistMarkerInt, 3));
        data.appendByte((byte) ((value >>> 56) & 0xff));
        data.appendByte((byte) ((value >>> 48) & 0xff));
        data.appendByte((byte) ((value >>> 40) & 0xff));
        data.appendByte((byte) ((value >>> 32) & 0xff));
        data.appendByte((byte) ((value >>> 24) & 0xff));
        data.appendByte((byte) ((value >>> 16) & 0xff));
        data.appendByte((byte) ((value >>> 8) & 0xff));
        data.appendByte((byte) ((value >>> 0) & 0xff));
      } else if (value > ShortMaxValue) {
        data.appendByte((byte) typeMarker(marker, 0x0f));
        data.appendByte((byte) typeMarker(Type.kCFBinaryPlistMarkerInt, 2));
        data.appendByte((byte) ((value >>> 24) & 0xff));
        data.appendByte((byte) ((value >>> 16) & 0xff));
        data.appendByte((byte) ((value >>> 8) & 0xff));
        data.appendByte((byte) ((value >>> 0) & 0xff));
      } else if (value > ByteMaxValue) {
        data.appendByte((byte) typeMarker(marker, 0x0f));
        data.appendByte((byte) typeMarker(Type.kCFBinaryPlistMarkerInt, 1));
        data.appendByte((byte) ((value >>> 8) & 0xff));
        data.appendByte((byte) ((value >>> 0) & 0xff));
      } else if (value >= 15) {
        data.appendByte((byte) typeMarker(marker, 0x0f));
        data.appendByte((byte) typeMarker(Type.kCFBinaryPlistMarkerInt, 0));
        data.appendByte((byte) ((value >>> 0) & 0xff));
      } else {
        data.appendByte((byte) typeMarker(marker, (byte) (value & 0x0f)));
      }
      return data.bytes();
    }
View Full Code Here

      public String toString() {
        return toString(2);
      }

      public String toString(int objectRefSize) {
        NSMutableData data = new NSMutableData(1024);
        appendToData(data, objectRefSize);
        return "[" + data.length() + "] " + data._hexString();
      }
View Full Code Here

     * string 0110 nnnn [int] ... // Unicode string, nnnn is # of chars, else 1111 then int count, then big-endian 2-byte shorts
     */

    private byte[] encodeString(String value) {
      try {
        NSMutableData data = new NSMutableData(value.length() * 2);
        String encoding = CharEncoding.UTF_8;
        // This is kind of funky we do a first encoding to see if we can get away with ASCII encoding
        // This is true if UTF-8 encoding yield the same length as the char count.
        byte[] theBytes = value.getBytes(encoding);
 
        if (theBytes.length == value.length()) {
          data.appendBytes(encodeCount(value.length(), Type.kCFBinaryPlistMarkerASCIIString));
        } else {
          if (Charset.isSupported("UTF-16BE")) {
            encoding = CharEncoding.UTF_16BE;
          }
          theBytes = value.getBytes(encoding);
          data.appendBytes(encodeCount(value.length(), Type.kCFBinaryPlistMarkerUnicode16String));
        }
        data.appendBytes(theBytes);
        return data.bytes();
      }
      catch (UnsupportedEncodingException e) {
        throw NSForwardException._runtimeExceptionForThrowable(e);
      }
    }
View Full Code Here

    /**
     * date 0011 0011 ... // 8 byte float follows, big-endian bytes
     */
    private byte[] encodeDate(Date value) {
      NSMutableData data = new NSMutableData(16);
      double convertedDate = _convertDate(value);
      data.appendByte((byte) typeMarker(Type.kCFBinaryPlistMarkerDate, 3));

      long bits = Double.doubleToRawLongBits(convertedDate);
      data.appendByte((byte) ((bits >>> 56) & 0xff));
      data.appendByte((byte) ((bits >>> 48) & 0xff));
      data.appendByte((byte) ((bits >>> 40) & 0xff));
      data.appendByte((byte) ((bits >>> 32) & 0xff));
      data.appendByte((byte) ((bits >>> 24) & 0xff));
      data.appendByte((byte) ((bits >>> 16) & 0xff));
      data.appendByte((byte) ((bits >>> 8) & 0xff));
      data.appendByte((byte) ((bits >>> 0) & 0xff));
      return data.bytes();
    }
View Full Code Here

    /*
     * data 0100 nnnn [int] ... // nnnn is number of bytes unless 1111 then int count follows, followed by bytes
     */
    private byte[] encodeData(byte[] theData) {
      NSMutableData data = new NSMutableData(theData.length + 8);
      data.appendBytes(encodeCount(theData.length, Type.kCFBinaryPlistMarkerData));
      data.appendBytes(theData);
      return data.bytes();
    }
View Full Code Here

TOP

Related Classes of com.webobjects.foundation.NSMutableData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.