Java Code Examples for java.io.ObjectInputStream#GetField

The following examples show how to use java.io.ObjectInputStream#GetField . 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
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new PropertyChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("propertyChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (PropertyChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
            for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 2
Source Project: JDKSourceCode1.8   File: InputStreamHook.java    License: MIT License 6 votes vote down vote up
public ObjectInputStream.GetField readFields()
    throws IOException, ClassNotFoundException, NotActiveException {

    HashMap fieldValueMap = new HashMap();

    // We were treating readFields same as defaultReadObject. It is
    // incorrect if the state is readOptionalData. If this line
    // is uncommented, it will throw a stream corrupted exception.
    // _REVISIT_: The ideal fix would be to add a new state. In
    // writeObject user may do one of the following
    // 1. Call defaultWriteObject()
    // 2. Put out optional fields
    // 3. Call writeFields
    // We have the state defined for (1) and (2) but not for (3), so
    // we should ideally introduce a new state for 3 and have the
    // beginDefaultReadObject do nothing.
    //readObjectState.beginDefaultReadObject(this);

    readFields(fieldValueMap);

    readObjectState.endDefaultReadObject(this);

    return new HookGetFields(fieldValueMap);
}
 
Example 3
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

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

    // Get permissions
    Hashtable<String, Vector<UnresolvedPermission>> permissions =
            (Hashtable<String, Vector<UnresolvedPermission>>)gfields.get("permissions", null);
    perms = new HashMap<String, List<UnresolvedPermission>>(permissions.size()*2);

    // Convert each entry (Vector) into a List
    Set<Map.Entry<String, Vector<UnresolvedPermission>>> set = permissions.entrySet();
    for (Map.Entry<String, Vector<UnresolvedPermission>> e : set) {
        // Convert Vector into ArrayList
        Vector<UnresolvedPermission> vec = e.getValue();
        List<UnresolvedPermission> list = new ArrayList<>(vec.size());
        list.addAll(vec);

        // Add to Hashtable being serialized
        perms.put(e.getKey(), list);
    }
}
 
Example 4
/**
 * Deserializes an {@link MBeanServerNotificationFilter} 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();
    selectedNames = cast(fields.get("mySelectObjNameList", null));
    if (fields.defaulted("mySelectObjNameList"))
    {
      throw new NullPointerException("mySelectObjNameList");
    }
    deselectedNames = cast(fields.get("myDeselectObjNameList", null));
    if (fields.defaulted("myDeselectObjNameList"))
    {
      throw new NullPointerException("myDeselectObjNameList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 5
/**
 * 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 6
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 7
Source Project: Java8CN   File: Locale.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes this <code>Locale</code>.
 * @param in the <code>ObjectInputStream</code> to read
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws IllformedLocaleException
 * @since 1.7
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = in.readFields();
    String language = (String)fields.get("language", "");
    String script = (String)fields.get("script", "");
    String country = (String)fields.get("country", "");
    String variant = (String)fields.get("variant", "");
    String extStr = (String)fields.get("extensions", "");
    baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
    if (extStr.length() > 0) {
        try {
            InternalLocaleBuilder bldr = new InternalLocaleBuilder();
            bldr.setExtensions(extStr);
            localeExtensions = bldr.getLocaleExtensions();
        } catch (LocaleSyntaxException e) {
            throw new IllformedLocaleException(e.getMessage());
        }
    } else {
        localeExtensions = null;
    }
}
 
Example 8
Source Project: jdk8u_jdk   File: Role.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 9
Source Project: j2objc   File: PropertyChangeSupport.java    License: Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new PropertyChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("propertyChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (PropertyChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
            for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 10
Source Project: ehcache3   File: GetFieldTest.java    License: Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  ObjectInputStream.GetField fields = in.readFields();
  if (!fields.defaulted("blargh")) {
    throw new Error();
  }
  try {
    fields.defaulted("nonexistant");
    throw new Error();
  } catch (IllegalArgumentException ex) {
  }
  if ((fields.get("z", false) != true)
          || (fields.get("b", (byte) 0) != 5)
          || (fields.get("c", '0') != '5')
          || (fields.get("s", (short) 0) != 5)
          || (fields.get("i", 0) != 5)
          || (fields.get("j", 0l) != 5)
          || (fields.get("f", 0.0f) != 5.0f)
          || (fields.get("d", 0.0) != 5.0)
          || (!fields.get("str", null).equals("5"))) {
    throw new Error();
  }
}
 
Example 11
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new VetoableChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>)fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("vetoableChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (VetoableChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
            for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 12
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

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

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

    // Convert each entry (Vector) into a List
    Set<Map.Entry<String, Vector<UnresolvedPermission>>> set = permissions.entrySet();
    for (Map.Entry<String, Vector<UnresolvedPermission>> e : set) {
        // Convert Vector into ArrayList
        Vector<UnresolvedPermission> vec = e.getValue();
        List<UnresolvedPermission> list = new ArrayList<>(vec.size());
        list.addAll(vec);

        // Add to Hashtable being serialized
        perms.put(e.getKey(), list);
    }
}
 
Example 13
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<Token> vChildren = (Vector<Token>)gf.get("children", null);

    //convert Vector back to List
    if (vChildren != null) children = new ArrayList<>(vChildren);
}
 
Example 14
Source Project: Java8CN   File: RoleUnresolved.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
/**
     * 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 16
/**
 * 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 17
@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 18
/**
 * Deserializes a {@link NumericValueExp} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    double doubleVal;
    long longVal;
    boolean isLong;
    ObjectInputStream.GetField fields = in.readFields();
    doubleVal = fields.get("doubleVal", (double)0);
    if (fields.defaulted("doubleVal"))
    {
      throw new NullPointerException("doubleVal");
    }
    longVal = fields.get("longVal", (long)0);
    if (fields.defaulted("longVal"))
    {
      throw new NullPointerException("longVal");
    }
    isLong = fields.get("valIsLong", false);
    if (fields.defaulted("valIsLong"))
    {
      throw new NullPointerException("valIsLong");
    }
    if (isLong)
    {
      this.val = longVal;
    }
    else
    {
      this.val = doubleVal;
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 19
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Class<? extends Annotation> t = (Class<? extends Annotation>)fields.get("type", null);
    @SuppressWarnings("unchecked")
    Map<String, Object> streamVals = (Map<String, Object>)fields.get("memberValues", null);

    // Check to make sure that types have not evolved incompatibly

    AnnotationType annotationType = null;
    try {
        annotationType = AnnotationType.getInstance(t);
    } catch(IllegalArgumentException e) {
        // Class is no longer an annotation type; time to punch out
        throw new java.io.InvalidObjectException("Non-annotation type in annotation serial stream");
    }

    Map<String, Class<?>> memberTypes = annotationType.memberTypes();
    // consistent with runtime Map type
    Map<String, Object> mv = new LinkedHashMap<>();

    // If there are annotation members without values, that
    // situation is handled by the invoke method.
    for (Map.Entry<String, Object> memberValue : streamVals.entrySet()) {
        String name = memberValue.getKey();
        Object value = null;
        Class<?> memberType = memberTypes.get(name);
        if (memberType != null) {  // i.e. member still exists
            value = memberValue.getValue();
            if (!(memberType.isInstance(value) ||
                  value instanceof ExceptionProxy)) {
                value = new AnnotationTypeMismatchExceptionProxy(
                        value.getClass() + "[" + value + "]").setMember(
                            annotationType.members().get(name));
            }
        }
        mv.put(name, value);
    }

    UnsafeAccessor.setType(this, t);
    UnsafeAccessor.setMemberValues(this, mv);
}
 
Example 20
/**
 * Deserializes a {@link NumericValueExp} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    double doubleVal;
    long longVal;
    boolean isLong;
    ObjectInputStream.GetField fields = in.readFields();
    doubleVal = fields.get("doubleVal", (double)0);
    if (fields.defaulted("doubleVal"))
    {
      throw new NullPointerException("doubleVal");
    }
    longVal = fields.get("longVal", (long)0);
    if (fields.defaulted("longVal"))
    {
      throw new NullPointerException("longVal");
    }
    isLong = fields.get("valIsLong", false);
    if (fields.defaulted("valIsLong"))
    {
      throw new NullPointerException("valIsLong");
    }
    if (isLong)
    {
      this.val = longVal;
    }
    else
    {
      this.val = doubleVal;
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}