Constructors Summary |
---|
public ObjectStreamField(String name, Class cl)Constructs an ObjectStreamField with the specified name and type.
if (name == null || cl == null) {
throw new NullPointerException();
}
this.name = name;
this.type = new WeakReference<Class<?>>(cl);
|
public ObjectStreamField(String name, Class cl, boolean unshared)Constructs an ObjectStreamField with the specified name, type and the
indication if it is unshared.
if (name == null || cl == null) {
throw new NullPointerException();
}
this.name = name;
this.type = (cl.getClassLoader() == null) ? cl
: new WeakReference<Class<?>>(cl);
this.unshared = unshared;
|
ObjectStreamField(String signature, String name)Constructs an ObjectStreamField with the given name and the given type.
The type may be null.
if (name == null) {
throw new NullPointerException();
}
this.name = name;
this.typeString = signature.replace('.", '/").intern();
this.isDeserialized = true;
|
Methods Summary |
---|
public int | compareTo(java.lang.Object o)Compares this field descriptor to the specified one. Checks first if one
of the compared fields has a primitive type and the other one not. If so,
the field with the primitive type is considered to be "smaller". If both
fields are equal, their names are compared.
ObjectStreamField f = (ObjectStreamField) o;
boolean thisPrimitive = this.isPrimitive();
boolean fPrimitive = f.isPrimitive();
// If one is primitive and the other isn't, we have enough info to
// compare
if (thisPrimitive != fPrimitive) {
return thisPrimitive ? -1 : 1;
}
// Either both primitives or both not primitives. Compare based on name.
return this.getName().compareTo(f.getName());
|
public java.lang.String | getName()Gets the name of this field.
return name;
|
public int | getOffset()Gets the offset of this field in the object.
return offset;
|
public java.lang.Class | getType()Gets the type of this field.
Class<?> cl = getTypeInternal();
if (isDeserialized && !cl.isPrimitive()) {
return Object.class;
}
return cl;
|
public char | getTypeCode()Gets a character code for the type of this field. The following codes are
used:
B byte
C char
D double
F float
I int
J long
L class or interface
S short
Z boolean
[ array
Class<?> t = getTypeInternal();
if (t == Integer.TYPE) {
return 'I";
}
if (t == Byte.TYPE) {
return 'B";
}
if (t == Character.TYPE) {
return 'C";
}
if (t == Short.TYPE) {
return 'S";
}
if (t == Boolean.TYPE) {
return 'Z";
}
if (t == Long.TYPE) {
return 'J";
}
if (t == Float.TYPE) {
return 'F";
}
if (t == Double.TYPE) {
return 'D";
}
if (t.isArray()) {
return '[";
}
return 'L";
|
java.lang.Class | getTypeInternal()Return the type of the field the receiver represents, this is an internal
method
if (type instanceof WeakReference) {
return (Class<?>) ((WeakReference<?>) type).get();
}
return (Class<?>) type;
|
public java.lang.String | getTypeString()Gets the type signature used by the VM to represent the type of this
field.
if (isPrimitive()) {
return null;
}
if (typeString == null) {
Class<?> t = getTypeInternal();
String typeName = t.getName().replace('.", '/");
String str = (t.isArray()) ? typeName : ("L" + typeName + ';"); //$NON-NLS-1$
typeString = str.intern();
}
return typeString;
|
public boolean | isPrimitive()Indicates whether this field's type is a primitive type.
Class<?> t = getTypeInternal();
return t != null && t.isPrimitive();
|
public boolean | isUnshared()Indicats whether this field is unshared.
return unshared;
|
void | resolve(java.lang.ClassLoader loader)
if (typeString.length() == 1) {
switch (typeString.charAt(0)) {
case 'I":
type = Integer.TYPE;
return;
case 'B":
type = Byte.TYPE;
return;
case 'C":
type = Character.TYPE;
return;
case 'S":
type = Short.TYPE;
return;
case 'Z":
type = Boolean.TYPE;
return;
case 'J":
type = Long.TYPE;
return;
case 'F":
type = Float.TYPE;
return;
case 'D":
type = Double.TYPE;
return;
}
}
String className = typeString.replace('/", '.");
if (className.charAt(0) == 'L") {
// remove L and ;
className = className.substring(1, className.length() - 1);
}
try {
Class<?> cl = Class.forName(className, false, loader);
type = (cl.getClassLoader() == null) ? cl
: new WeakReference<Class<?>>(cl);
} catch (ClassNotFoundException e) {
// Ignored
}
|
protected void | setOffset(int newValue)Sets this field's offset in the object.
this.offset = newValue;
|
void | setUnshared(boolean unshared)
this.unshared = unshared;
|
static void | sortFields(java.io.ObjectStreamField[] fields)Sorts the fields for dumping. Primitive types come first, then regular
types.
// Sort if necessary
if (fields.length > 1) {
Comparator<ObjectStreamField> fieldDescComparator = new Comparator<ObjectStreamField>() {
public int compare(ObjectStreamField f1, ObjectStreamField f2) {
return f1.compareTo(f2);
}
};
Arrays.sort(fields, fieldDescComparator);
}
|
public java.lang.String | toString()Returns a string containing a concise, human-readable description of this
field descriptor.
return this.getClass().getName() + '(" + getName() + ':"
+ getTypeInternal() + ')";
|