Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.io;
 
A description of a Serializable field from a Serializable class. An array of ObjectStreamFields is used to declare the Serializable fields of a class.

Author(s):
Mike Warres
Roger Riggs
Since:
1.2
See also:
ObjectStreamClass
 
 public class ObjectStreamField
     implements Comparable<Object>
 {

    
field name
 
     private final String name;
    
canonical JVM signature of field type
 
     private final String signature;
    
field type (Object.class if unknown non-primitive type)
 
     private final Class type;
    
whether or not to (de)serialize field values as unshared
 
     private final boolean unshared;
    
corresponding reflective field object, if any
 
     private final Field field;
    
offset of field value in enclosing field group
 
     private int offset = 0;

    
Create a Serializable field with the specified type. This field should be documented with a serialField tag.

Parameters:
name the name of the serializable field
type the Class object of the serializable field
 
     public ObjectStreamField(String nameClass<?> type) {
         this(nametypefalse);
     }

    
Creates an ObjectStreamField representing a serializable field with the given name and type. If unshared is false, values of the represented field are serialized and deserialized in the default manner--if the field is non-primitive, object values are serialized and deserialized as if they had been written and read by calls to writeObject and readObject. If unshared is true, values of the represented field are serialized and deserialized as if they had been written and read by calls to writeUnshared and readUnshared.

Parameters:
name field name
type field type
unshared if false, write/read field values in the same manner as writeObject/readObject; if true, write/read in the same manner as writeUnshared/readUnshared
Since:
1.4
 
     public ObjectStreamField(String nameClass<?> typeboolean unshared) {
         if (name == null) {
             throw new NullPointerException();
         }
         this. = name;
         this. = type;
         this. = unshared;
          = ObjectStreamClass.getClassSignature(type).intern();
          = null;
     }

    
Creates an ObjectStreamField representing a field with the given name, signature and unshared setting.
 
     ObjectStreamField(String nameString signatureboolean unshared) {
        if (name == null) {
            throw new NullPointerException();
        }
        this. = name;
        this. = signature.intern();
        this. = unshared;
         = null;
        switch (signature.charAt(0)) {
            case 'Z' = .break;
            case 'B' = .break;
            case 'C' = .break;
            case 'S' = .break;
            case 'I' = .break;
            case 'J' = .break;
            case 'F' = .break;
            case 'D' = .break;
            case 'L':
            case '[' = Object.classbreak;
            defaultthrow new IllegalArgumentException("illegal signature");
        }
    }

    
Creates an ObjectStreamField representing the given field with the specified unshared setting. For compatibility with the behavior of earlier serialization implementations, a "showType" parameter is necessary to govern whether or not a getType() call on this ObjectStreamField (if non-primitive) will return Object.class (as opposed to a more specific reference type).
    ObjectStreamField(Field fieldboolean unsharedboolean showType) {
        this. = field;
        this. = unshared;
         = field.getName();
        Class ftype = field.getType();
         = (showType || ftype.isPrimitive()) ? ftype : Object.class;
         = ObjectStreamClass.getClassSignature(ftype).intern();
    }

    
Get the name of this field.

Returns:
a String representing the name of the serializable field
    public String getName() {
        return ;
    }

    
Get the type of the field. If the type is non-primitive and this ObjectStreamField was obtained from a deserialized ObjectStreamClass instance, then Object.class is returned. Otherwise, the Class object for the type of the field is returned.

Returns:
a Class object representing the type of the serializable field
    public Class<?> getType() {
        return ;
    }

    
Returns character encoding of field type. The encoding is as follows:
 B            byte
 C            char
 D            double
 F            float
 I            int
 J            long
 L            class or interface
 S            short
 Z            boolean
 [            array
 

Returns:
the typecode of the serializable field
    // REMIND: deprecate?
    public char getTypeCode() {
        return .charAt(0);
    }

    
Return the JVM type signature.

Returns:
null if this field has a primitive type.
    // REMIND: deprecate?
    public String getTypeString() {
        return isPrimitive() ? null : ;
    }

    
Offset of field within instance data.

Returns:
the offset of this field
See also:
setOffset(int)
    // REMIND: deprecate?
    public int getOffset() {
        return ;
    }

    
Offset within instance data.

Parameters:
offset the offset of the field
See also:
getOffset()
    // REMIND: deprecate?
    protected void setOffset(int offset) {
        this. = offset;
    }

    
Return true if this field has a primitive type.

Returns:
true if and only if this field corresponds to a primitive type
    // REMIND: deprecate?
    public boolean isPrimitive() {
        char tcode = .charAt(0);
        return ((tcode != 'L') && (tcode != '['));
    }

    
Returns boolean value indicating whether or not the serializable field represented by this ObjectStreamField instance is unshared.

Since:
1.4
    public boolean isUnshared() {
        return ;
    }

    
Compare this field with another ObjectStreamField. Return -1 if this is smaller, 0 if equal, 1 if greater. Types that are primitives are "smaller" than object types. If equal, the field names are compared.
    // REMIND: deprecate?
    public int compareTo(Object obj) {
        ObjectStreamField other = (ObjectStreamFieldobj;
        boolean isPrim = isPrimitive();
        if (isPrim != other.isPrimitive()) {
            return isPrim ? -1 : 1;
        }
        return .compareTo(other.name);
    }

    
Return a string that describes this field.
    public String toString() {
        return  + ' ' + ;
    }

    
Returns field represented by this ObjectStreamField, or null if ObjectStreamField is not associated with an actual field.
    Field getField() {
        return ;
    }

    
Returns JVM type signature of field (similar to getTypeString, except that signature strings are returned for primitive fields as well).
    String getSignature() {
        return ;
    }
New to GrepCode? Check out our FAQ X