java.io.ObjectStreamField Java Examples
The following examples show how to use
java.io.ObjectStreamField.
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
Source File: ValueType.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #2
Source File: ObjectStreamFieldTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.io.ObjectStreamField#getType() */ public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new SerializableObject()); oos.close(); baos.close(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); MockObjectInputStream ois = new MockObjectInputStream(bais); ois.readObject(); ObjectStreamClass oc = ois.getObjectStreamClass(); ObjectStreamField field = oc.getField("i"); assertEquals(Object.class, field.getType()); }
Example #3
Source File: ObjectStreamFieldTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.io.ObjectStreamField#getType() */ public void test_getType_Deserialized() throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(new SerializableObject()); oos.close(); baos.close(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); SerializableObject obj = (SerializableObject) ois.readObject(); ObjectStreamClass oc = obj.getObjectStreamClass(); ObjectStreamField field = oc.getField("i"); assertEquals(Object.class, field.getType()); }
Example #4
Source File: ObjectStreamClassTest.java From j2objc with Apache License 2.0 | 6 votes |
public void test_specialTypes() { Class<?> proxyClass = Proxy.getProxyClass(this.getClass() .getClassLoader(), new Class[] { Runnable.class }); ObjectStreamClass proxyStreamClass = ObjectStreamClass .lookup(proxyClass); assertEquals("Proxy classes should have zero serialVersionUID", 0, proxyStreamClass.getSerialVersionUID()); ObjectStreamField[] proxyFields = proxyStreamClass.getFields(); assertEquals("Proxy classes should have no serialized fields", 0, proxyFields.length); ObjectStreamClass enumStreamClass = ObjectStreamClass .lookup(Thread.State.class); assertEquals("Enum classes should have zero serialVersionUID", 0, enumStreamClass.getSerialVersionUID()); ObjectStreamField[] enumFields = enumStreamClass.getFields(); assertEquals("Enum classes should have no serialized fields", 0, enumFields.length); }
Example #5
Source File: ValueType.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #6
Source File: ValueType.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #7
Source File: ValueType.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #8
Source File: ValueType.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #9
Source File: ValueType.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #10
Source File: ValueType.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #11
Source File: ValueType.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Get the names and types of all the persistent fields of a Class. */ private Hashtable getPersistentFields (Class clz) { Hashtable result = new Hashtable(); ObjectStreamClass osc = ObjectStreamClass.lookup(clz); if (osc != null) { ObjectStreamField[] fields = osc.getFields(); for (int i = 0; i < fields.length; i++) { String typeSig; String typePrefix = String.valueOf(fields[i].getTypeCode()); if (fields[i].isPrimitive()) { typeSig = typePrefix; } else { if (fields[i].getTypeCode() == '[') { typePrefix = ""; } typeSig = typePrefix + fields[i].getType().getName().replace('.','/'); if (typeSig.endsWith(";")) { typeSig = typeSig.substring(0,typeSig.length()-1); } } result.put(fields[i].getName(),typeSig); } } return result; }
Example #12
Source File: ObjectStreamClassTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.io.ObjectStreamClass#getFields() */ public void test_getFields() { ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class); ObjectStreamField[] osfArray = osc.getFields(); assertTrue( "Array of fields should be of length 2 but is instead of length: " + osfArray.length, osfArray.length == 2); }
Example #13
Source File: ObjectStreamFieldTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.io.ObjectStreamField#getOffset() */ public void test_getOffset() { ObjectStreamField[] osfArray; osfArray = osc.getFields(); assertTrue("getOffset did not return reasonable values", osfArray[0] .getOffset() != osfArray[1].getOffset()); assertEquals("getOffset for osfArray[0].getOffset() did not return 0", 0, osfArray[0].getOffset()); assertEquals("osfArray[1].getOffset() did not return 8", 8, osfArray[1] .getOffset()); assertEquals("osfArray[2].getOffset() did not return 12", 12, osfArray[2].getOffset()); }
Example #14
Source File: ObjectStreamFieldTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.io.ObjectStreamField#getTypeString() */ public void test_getTypeString() { assertTrue("getTypeString returned: " + holaField.getTypeString(), holaField.getTypeString().indexOf("Object") >= 0); assertNull("Primitive types' strings should be null", hamField .getTypeString()); ObjectStreamField osf = new ObjectStreamField("s", String.class, true); assertTrue(osf.getTypeString() == "Ljava/lang/String;"); }
Example #15
Source File: SerializableDemo.java From Learn-Java-12-Programming with MIT License | 5 votes |
private static void printInfo(ObjectStreamClass osc) { System.out.println(osc.forClass()); System.out.println("Class name: " + osc.getName()); System.out.println("SerialVersionUID: " + osc.getSerialVersionUID()); ObjectStreamField[] fields = osc.getFields(); System.out.println("Serialized fields:"); for (ObjectStreamField osf : fields) { System.out.println(osf.getName() + ": "); System.out.println("\t" + osf.getType()); System.out.println("\t" + osf.getTypeCode()); System.out.println("\t" + osf.getTypeString()); System.out.println("\t" + osf.getOffset()); } }
Example #16
Source File: SerializationTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSerializeFieldMadeTransient() throws Exception { // Does ObjectStreamClass have the right idea? ObjectStreamClass osc = ObjectStreamClass.lookup(FieldMadeTransient.class); ObjectStreamField[] fields = osc.getFields(); assertEquals(1, fields.length); assertEquals("nonTransientInt", fields[0].getName()); assertEquals(int.class, fields[0].getType()); // this was created by serializing a FieldMadeTransient with a non-0 transientInt String s = "aced0005737200346c6962636f72652e6a6176612e696f2e53657269616c697a6174696f6e54657" + "374244669656c644d6164655472616e7369656e74000000000000000002000149000c7472616e736" + "9656e74496e747870abababab"; FieldMadeTransient deserialized = (FieldMadeTransient) SerializationTester.deserializeHex(s); assertEquals(0, deserialized.transientInt); }
Example #17
Source File: OldObjectStreamFieldTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_getOffset() { ObjectStreamField[] osfArray; osfArray = osc.getFields(); int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0}; assertTrue("getOffset() did not return reasonable values.", osfArray[0] .getOffset() != osfArray[1].getOffset()); for (int i = 0; i < expectedOffsets.length; i++) { assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i), expectedOffsets[i], osfArray[i].getOffset()); } }
Example #18
Source File: OldObjectStreamFieldTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_isPrimitive() { // Test for method int java.io.ObjectStreamField.getOffset() ObjectStreamField[] osfArray; osfArray = osc.getFields(); for (int i = 0; i < (osfArray.length - 1); i++) { assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i), osfArray[i].isPrimitive()); } assertFalse(String.format("osfArray[%d].isPrimitive() should return false.", osfArray.length - 1), osfArray[(osfArray.length - 1)].isPrimitive()); }
Example #19
Source File: SerializableConverter.java From lams with GNU General Public License v2.0 | 4 votes |
private Object readField(ObjectStreamField field, Class type, Object instance) { Field javaField = Fields.find(type, field.getName()); return Fields.read(javaField, instance); }