Package com.webobjects.foundation

Examples of com.webobjects.foundation.NSData


   * @see #propertyListFromData(NSData, java.lang.String)
   */
  public static NSData dataFromPropertyList(Object plist, String encoding) {
    if (plist == null)
      return null;
    return new NSData(_NSStringUtilities.bytesForString(stringFromPropertyList(plist), encoding));
  }
View Full Code Here


          }
        }
        if (attribute().className().contains("NSTimestamp")) {
          return new NSTimestamp(DateTools.stringToDate(value));
        } else if (attribute().className().contains("NSData")) {
          return new NSData((NSData) NSPropertyListSerialization.propertyListFromString(value));
        } else if (attribute().className().contains("NSArray")) {
          return NSArray.componentsSeparatedByString(value, " ");
        }
        return value.toString();
      } catch (ParseException ex) {
View Full Code Here

        try {
          pkValue = ERXEOControlUtilities.primaryKeyObjectForObject(eo);
          if (pkValue == null) {
            EOGlobalID gid = editingContext.globalIDForObject(eo);
            if (gid instanceof EOTemporaryGlobalID) {
              pkValue = new NSData(((EOTemporaryGlobalID) gid)._rawBytes());
            }
          }
        }
        finally {
          editingContext.unlock();
View Full Code Here

//          pkValue = new NSData(buf.getRawData());
//        } catch (IOException e) {
//          throw NSForwardException._runtimeExceptionForThrowable(e);
//        }
//      } else {
        pkValue = new NSData(new EOTemporaryGlobalID()._rawBytes());
//      }
    } else {
      throw new IllegalArgumentException("Unknown value type '" + valueType + "' for '" + object + "' of entity '" + entity.name() + "'.");
    }
    NSDictionary pk = new NSDictionary<String, Object>(pkValue, pkAttribute.name());
View Full Code Here

        throw new IOException("Property list input stream cannot be null");
      }
      boolean parsed = false;
      BufferedInputStream bis = new BufferedInputStream(is);

      NSData data = new NSData(bis, -1); // bigger chunk size?
      byte[] theBytes = data.bytes();

      // Parse the HEADER
      // ----------------
      // magic number ("bplist")
      // file format version ("00")
View Full Code Here

     * @param index
     * @param count
     * @throws IOException
     */
    private void parseData(byte[] bytes, int index, int count) throws IOException {
      objectTable.add(new NSData(bytes, index, count));
    }
View Full Code Here

    try {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(bout);
      oos.writeObject(d);
      oos.close();
      NSData sp = new NSData(bout.toByteArray());
      return sp;
    } catch (IOException e) {
      // shouldn't ever happen, as we only write to memory
      throw NSForwardException._runtimeExceptionForThrowable(e);
    }
View Full Code Here

              if(rawValue instanceof NSMutableData) {
                  // AK: wtf!! I got an exception
                  // java.lang.IllegalArgumentException: Attempt to create an EOGlobalID for the entity "Asset" with a primary key component of type com.webobjects.foundation.NSMutableData instead of type com.webobjects.foundation.NSData!
                  // so this is a lame attempt to fix it.
                 
                rawValue = new NSData((NSMutableData)rawValue);
              }
                EOAttribute attribute = pks.objectAtIndex(0);
                Object value = rawValue;
                value = attribute.validateValue(value);
                pk.setObjectForKey(value, attribute.name());
View Full Code Here

                } else {
                    anInstance.setRefusingNewSessions(false);
                }

                NSDictionary instanceResponse = null;
                NSData responseContent = aResponse.content();
                try {
                    instanceResponse = (NSDictionary) new _JavaMonitorDecoder().decodeRootObject(responseContent);
                } catch (WOXMLException wxe) {
                    try {
                        Object o = NSPropertyListSerialization.propertyListFromString(new String(responseContent.bytes()));
                        errorResponse.addObject(anInstance.displayName() + " is probably an older application that doesn't conform to the current Monitor Protocol. Please update and restart the instance.");
                        NSLog.err.appendln("Got old-style response from instance: " + anInstance.displayName());
                    } catch (Throwable t) {
                        NSLog.err.appendln("Wotaskd getStatisticsForInstanceArray: Error parsing: " + new String(responseContent.bytes()) + " from " + anInstance.displayName());
                    }
                    continue;
                } catch (NullPointerException npe) {
                    NSLog.err.appendln("Wotaskd getStatisticsForInstanceArray: No content returned from " + anInstance.displayName());
                    continue;
View Full Code Here

   *            default value if object is null
   * @return NSData evaluation of the given object
   *
   */
  public static NSData dataValueWithDefault(Object obj, NSData def) {
    NSData value = def;
    if (!ERXValueUtilities.isNull(obj)) {
      if (obj instanceof NSData) {
        value = (NSData) obj;
      } else if (obj instanceof byte[]) {
        byte[] byteValue = (byte[]) obj;
        value = new NSData(byteValue, new NSRange(0, byteValue.length), true);
      } else if (obj instanceof String) {
        String strValue = ((String) obj).trim();
        if (strValue.length() > 0) {
          Object objValue = NSPropertyListSerialization.propertyListFromString(strValue); // MS:
                                                  // Encoding?
          if (objValue == null || !(objValue instanceof NSData)) {
            throw new IllegalArgumentException("Failed to parse data from the value '" + obj + "'.");
          }
          value = (NSData) objValue;
          if (value instanceof NSMutableData) {
            // AK: we need NSData if we want to use it for a PK, but
            // we get NSMutableData
            value = new NSData(value);
          }
        }
      } else {
        throw new IllegalArgumentException("Failed to parse data from the value '" + obj + "'.");
      }
View Full Code Here

TOP

Related Classes of com.webobjects.foundation.NSData

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.