Java Code Examples for java.io.ObjectInputStream#readFields()

The following examples show how to use java.io.ObjectInputStream#readFields() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Deserializes an {@link OpenType} from an {@link java.io.ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
    checkClassNameOverride();
    ObjectInputStream.GetField fields = in.readFields();
    final String classNameField;
    final String descriptionField;
    final String typeNameField;
    try {
        classNameField =
            validClassName((String) fields.get("className", null));
        descriptionField =
            valid("description", (String) fields.get("description", null));
        typeNameField =
            valid("typeName", (String) fields.get("typeName", null));
    } catch (Exception e) {
        IOException e2 = new InvalidObjectException(e.getMessage());
        e2.initCause(e);
        throw e2;
    }
    className = classNameField;
    description = descriptionField;
    typeName = typeNameField;
    isArray = (className.startsWith("["));
}
 
Example 2
/**
 * Deserializes a {@link RoleResult} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    roleList = (RoleList) fields.get("myRoleList", null);
    if (fields.defaulted("myRoleList"))
    {
      throw new NullPointerException("myRoleList");
    }
    unresolvedRoleList = (RoleUnresolvedList) fields.get("myRoleUnresList", null);
    if (fields.defaulted("myRoleUnresList"))
    {
      throw new NullPointerException("myRoleUnresList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 3
/**
 * Deserializes a {@link RoleResult} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    roleList = (RoleList) fields.get("myRoleList", null);
    if (fields.defaulted("myRoleList"))
    {
      throw new NullPointerException("myRoleList");
    }
    unresolvedRoleList = (RoleUnresolvedList) fields.get("myRoleUnresList", null);
    if (fields.defaulted("myRoleUnresList"))
    {
      throw new NullPointerException("myRoleUnresList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 4
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get allPermission
    allPermission = (PermissionCollection) gfields.get("allPermission", null);

    // Get permissions
    // writeObject writes a Hashtable<Class<?>, PermissionCollection> for
    // the perms key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<Class<?>, PermissionCollection> perms =
        (Hashtable<Class<?>, PermissionCollection>)gfields.get("perms", null);
    permsMap = new HashMap<Class<?>, PermissionCollection>(perms.size()*2);
    permsMap.putAll(perms);

    // Set hasUnresolved
    UnresolvedPermissionCollection uc =
    (UnresolvedPermissionCollection) permsMap.get(UnresolvedPermission.class);
    hasUnresolved = (uc != null && uc.elements().hasMoreElements());
}
 
Example 5
/**
 * readObject is called to restore the state of the
 * {@code BatchUpdateException} from a stream.
 */
private void readObject(ObjectInputStream s)
        throws IOException, ClassNotFoundException {

   ObjectInputStream.GetField fields = s.readFields();
   int[] tmp = (int[])fields.get("updateCounts", null);
   long[] tmp2 = (long[])fields.get("longUpdateCounts", null);
   if(tmp != null && tmp2 != null && tmp.length != tmp2.length)
       throw new InvalidObjectException("update counts are not the expected size");
   if (tmp != null)
       updateCounts = tmp.clone();
   if (tmp2 != null)
       longUpdateCounts = tmp2.clone();
   if(updateCounts == null && longUpdateCounts != null)
       updateCounts = copyUpdateCount(longUpdateCounts);
   if(longUpdateCounts == null && updateCounts != null)
       longUpdateCounts = copyUpdateCount(updateCounts);

}
 
Example 6
/**
 * Deserializes a {@link Role} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    name = (String) fields.get("myName", null);
    if (fields.defaulted("myName"))
    {
      throw new NullPointerException("myName");
    }
    objectNameList = cast(fields.get("myObjNameList", null));
    if (fields.defaulted("myObjNameList"))
    {
      throw new NullPointerException("myObjNameList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 7
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permissions
    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyPermission> permissions =
        (Hashtable<String, PropertyPermission>)gfields.get("permissions", null);
    perms = new HashMap<>(permissions.size()*2);
    perms.putAll(permissions);
}
 
Example 8
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example 9
Source Project: ironjacamar   File: WorkEvent.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Read object
 * @param ois The object input stream
 * @exception ClassNotFoundException If a class can not be found
 * @exception IOException Thrown if an error occurs
 */
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
{
   ObjectInputStream.GetField fields = ois.readFields();
   String name = serialPersistentFields[TYPE_IDX].getName();
   this.type = fields.get(name, 0);
   name = serialPersistentFields[WORK_IDX].getName();
   this.work = (Work) fields.get(name, null);
   name = serialPersistentFields[EXCPEPTION_IDX].getName();
   this.e = (WorkException) fields.get(name, null);
   name = serialPersistentFields[DURATION_IDX].getName();
   this.startDuration = fields.get(name, 0L);
}
 
Example 10
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call in.defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get the one we want
    @SuppressWarnings("unchecked")
    Vector<SocketPermission> permissions = (Vector<SocketPermission>)gfields.get("permissions", null);
    perms = new ArrayList<SocketPermission>(permissions.size());
    perms.addAll(permissions);
}
 
Example 11
/**
 * Deserializes a {@link RoleUnresolved} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    roleName = (String) fields.get("myRoleName", null);
    if (fields.defaulted("myRoleName"))
    {
      throw new NullPointerException("myRoleName");
    }
    roleValue = cast(fields.get("myRoleValue", null));
    if (fields.defaulted("myRoleValue"))
    {
      throw new NullPointerException("myRoleValue");
    }
    problemType = fields.get("myPbType", 0);
    if (fields.defaulted("myPbType"))
    {
      throw new NullPointerException("myPbType");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 12
Source Project: jdk8u-jdk   File: Window.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads the {@code ObjectInputStream} and an optional
 * list of listeners to receive various events fired by
 * the component; also reads a list of
 * (possibly {@code null}) child windows.
 * Unrecognized keys or values will be ignored.
 *
 * @param s the {@code ObjectInputStream} to read
 * @exception HeadlessException if
 *   {@code GraphicsEnvironment.isHeadless} returns
 *   {@code true}
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @see #writeObject
 */
private void readObject(ObjectInputStream s)
  throws ClassNotFoundException, IOException, HeadlessException
{
     GraphicsEnvironment.checkHeadless();
     initDeserializedWindow();
     ObjectInputStream.GetField f = s.readFields();

     syncLWRequests = f.get("syncLWRequests", systemSyncLWRequests);
     state = f.get("state", 0);
     focusableWindowState = f.get("focusableWindowState", true);
     windowSerializedDataVersion = f.get("windowSerializedDataVersion", 1);
     locationByPlatform = f.get("locationByPlatform", locationByPlatformProp);
     // Note: 1.4 (or later) doesn't use focusMgr
     focusMgr = (FocusManager)f.get("focusMgr", null);
     Dialog.ModalExclusionType et = (Dialog.ModalExclusionType)
         f.get("modalExclusionType", Dialog.ModalExclusionType.NO_EXCLUDE);
     setModalExclusionType(et); // since 6.0
     boolean aot = f.get("alwaysOnTop", false);
     if(aot) {
         setAlwaysOnTop(aot); // since 1.5; subject to permission check
     }
     shape = (Shape)f.get("shape", null);
     opacity = (Float)f.get("opacity", 1.0f);

     this.securityWarningWidth = 0;
     this.securityWarningHeight = 0;
     this.securityWarningPointX = 2.0;
     this.securityWarningPointY = 0.0;
     this.securityWarningAlignmentX = RIGHT_ALIGNMENT;
     this.securityWarningAlignmentY = TOP_ALIGNMENT;

     deserializeResources(s);
}
 
Example 13
private void readObject (ObjectInputStream s) throws
                     IOException, ClassNotFoundException {
    if (getClass().getClassLoader() != null) {
        throw new SecurityException ("invalid address type");
    }
    GetField gf = s.readFields();
    String host = (String)gf.get("hostName", null);
    int address = gf.get("address", 0);
    int family = gf.get("family", 0);
    if (family != IPv4 && family != IPv6) {
        throw new InvalidObjectException("invalid address family type: " + family);
    }
    InetAddressHolder h = new InetAddressHolder(host, address, family);
    UNSAFE.putObject(this, FIELDS_OFFSET, h);
}
 
Example 14
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get the one we want
    Vector<Permission> permissions =
            (Vector<Permission>)gfields.get("permissions", null);
    perms = new ArrayList<Permission>(permissions.size());
    perms.addAll(permissions);
}
 
Example 15
private void readObject(ObjectInputStream s)
    throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = s.readFields();
    @SuppressWarnings("unchecked")
    Hashtable<String,PermissionCollection> permTable =
            (Hashtable<String,PermissionCollection>)
            (fields.get("perms", null));
    if (permTable != null) {
        perms = new ConcurrentHashMap<>(permTable);
    } else {
        perms = new ConcurrentHashMap<>();
    }
}
 
Example 16
/**
     * Reads default serializable fields to stream.
     * @exception HeadlessException if
     * <code>GraphicsEnvironment.isHeadless()</code> returns
     * <code>true</code>
     * @see java.awt.GraphicsEnvironment#isHeadless
     */
    private void readObject(ObjectInputStream s)
        throws ClassNotFoundException, IOException, HeadlessException
    {
        GraphicsEnvironment.checkHeadless();
        // 4352819: Gotcha!  Cannot use s.defaultReadObject here and
        // then continue with reading optional data.  Use GetField instead.
        ObjectInputStream.GetField f = s.readFields();

        // Old fields
        scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
                                       SCROLLBARS_AS_NEEDED);
        hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
        vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);

        // Since 1.4
        wheelScrollingEnabled = f.get("wheelScrollingEnabled",
                                      defaultWheelScroll);

//      // Note to future maintainers
//      if (f.defaulted("wheelScrollingEnabled")) {
//          // We are reading pre-1.4 stream that doesn't have
//          // optional data, not even the TC_ENDBLOCKDATA marker.
//          // Reading anything after this point is unsafe as we will
//          // read unrelated objects further down the stream (4352819).
//      }
//      else {
//          // Reading data from 1.4 or later, it's ok to try to read
//          // optional data as OptionalDataException with eof == true
//          // will be correctly reported
//      }
    }
 
Example 17
private void readObject(ObjectInputStream  inputStream) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField gf = inputStream.readFields();
    String h = (String)gf.get("host", null);
    int p = (int)gf.get("port", -1);
    String proto = (String)gf.get("protocol", null);
    String url = (String)gf.get("urlPath", null);

    if (proto == null || url == null || h == null) {
        StringBuilder sb = new StringBuilder(INVALID_INSTANCE_MSG).append('[');
        boolean empty = true;
        if (proto == null) {
            sb.append("protocol=null");
            empty = false;
        }
        if (h == null) {
            sb.append(empty ? "" : ",").append("host=null");
            empty = false;
        }
        if (url == null) {
            sb.append(empty ? "" : ",").append("urlPath=null");
        }
        sb.append(']');
        throw new InvalidObjectException(sb.toString());
    }

    if (h.contains("[") || h.contains("]")) {
        throw new InvalidObjectException("Invalid host name: " + h);
    }

    try {
        validate(proto, h, p, url);
        this.protocol = proto;
        this.host = h;
        this.port = p;
        this.urlPath = url;
    } catch (MalformedURLException e) {
        throw new InvalidObjectException(INVALID_INSTANCE_MSG + ": " +
                                         e.getMessage());
    }

}
 
Example 18
/**
 * Deserializes a {@link RoleInfo} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    name = (String) fields.get("myName", null);
    if (fields.defaulted("myName"))
    {
      throw new NullPointerException("myName");
    }
    isReadable = fields.get("myIsReadableFlg", false);
    if (fields.defaulted("myIsReadableFlg"))
    {
      throw new NullPointerException("myIsReadableFlg");
    }
    isWritable = fields.get("myIsWritableFlg", false);
    if (fields.defaulted("myIsWritableFlg"))
    {
      throw new NullPointerException("myIsWritableFlg");
    }
    description = (String) fields.get("myDescription", null);
    if (fields.defaulted("myDescription"))
    {
      throw new NullPointerException("myDescription");
    }
    minDegree = fields.get("myMinDegree", 0);
    if (fields.defaulted("myMinDegree"))
    {
      throw new NullPointerException("myMinDegree");
    }
    maxDegree = fields.get("myMaxDegree", 0);
    if (fields.defaulted("myMaxDegree"))
    {
      throw new NullPointerException("myMaxDegree");
    }
    referencedMBeanClassName = (String) fields.get("myRefMBeanClassName", null);
    if (fields.defaulted("myRefMBeanClassName"))
    {
      throw new NullPointerException("myRefMBeanClassName");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 19
private void readObject(ObjectInputStream s)
    throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField f = s.readFields();

    int newMessageType = f.get("messageType", 0);
    checkMessageType(newMessageType);
    messageType = newMessageType;
    int newOptionType = f.get("optionType", 0);
    checkOptionType(newOptionType);
    optionType = newOptionType;
    wantsInput = f.get("wantsInput", false);

    Vector<?>       values = (Vector)s.readObject();
    int             indexCounter = 0;
    int             maxCounter = values.size();

    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("icon")) {
        icon = (Icon)values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("message")) {
        message = values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("options")) {
        options = (Object[])values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("initialValue")) {
        initialValue = values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("value")) {
        value = values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("selectionValues")) {
        selectionValues = (Object[])values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("inputValue")) {
        inputValue = values.elementAt(++indexCounter);
        indexCounter++;
    }
    if(indexCounter < maxCounter && values.elementAt(indexCounter).
       equals("initialSelectionValue")) {
        initialSelectionValue = values.elementAt(++indexCounter);
        indexCounter++;
    }
    if (getUIClassID().equals(uiClassID)) {
        byte count = JComponent.getWriteObjCounter(this);
        JComponent.setWriteObjCounter(this, --count);
        if (count == 0 && ui != null) {
            ui.installUI(this);
        }
    }
}
 
Example 20
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField gf = ois.readFields();
    String[] t = (String[])gf.get("types", null);

    types = (t != null && t.length != 0) ? t.clone() : NO_TYPES;
}