Java Code Examples for java.io.ObjectStreamClass#getSerialVersionUID()

The following examples show how to use java.io.ObjectStreamClass#getSerialVersionUID() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 2
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 3
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 4
/**
 * Updates the options that the current classifier is using.
 */
@Override
protected void updateOptions() {

  if (m_Template instanceof OptionHandler) {
    m_ClassifierOptions = Utils.joinOptions(((OptionHandler) m_Template)
        .getOptions());
  } else {
    m_ClassifierOptions = "";
  }
  if (m_Template instanceof Serializable) {
    ObjectStreamClass obs = ObjectStreamClass.lookup(m_Template.getClass());
    m_ClassifierVersion = "" + obs.getSerialVersionUID();
  } else {
    m_ClassifierVersion = "";
  }
}
 
Example 5
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 6
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 7
Source Project: Flink-CEPplus   File: InstantiationUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
	ObjectStreamClass streamClassDescriptor = super.readClassDescriptor();

	try {
		Class.forName(streamClassDescriptor.getName(), false, classLoader);
	} catch (ClassNotFoundException e) {

		final ObjectStreamClass equivalentSerializer =
				MigrationUtil.getEquivalentSerializer(streamClassDescriptor.getName());

		if (equivalentSerializer != null) {
			return equivalentSerializer;
		}
	}

	final Class localClass = resolveClass(streamClassDescriptor);
	final String name = localClass.getName();
	if (scalaSerializerClassnames.contains(name) || scalaTypes.contains(name) || isAnonymousClass(localClass)
		|| isOldAvroSerializer(name, streamClassDescriptor.getSerialVersionUID())) {
		final ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
		if (localClassDescriptor != null
			&& localClassDescriptor.getSerialVersionUID() != streamClassDescriptor.getSerialVersionUID()) {
			LOG.warn("Ignoring serialVersionUID mismatch for class {}; was {}, now {}.",
				streamClassDescriptor.getName(), streamClassDescriptor.getSerialVersionUID(), localClassDescriptor.getSerialVersionUID());

			streamClassDescriptor = localClassDescriptor;
		}
	}

	return streamClassDescriptor;
}
 
Example 8
Source Project: j2objc   File: ObjectStreamFieldTest.java    License: Apache License 2.0 5 votes vote down vote up
public ObjectStreamClass readClassDescriptor() throws IOException,
        ClassNotFoundException {
    ObjectStreamClass osc = super.readClassDescriptor();
    // To get the ObjectStreamClass of SerializableObject
    if (osc.getSerialVersionUID() == -2953957835918368056L) {
        temp = osc;
    }
    return osc;
}
 
Example 9
public SerializableDataKey(ObjectStreamClass desc, boolean store) throws IOException {
  Class<?> forClass = desc.forClass();
  if (forClass != null) {
    if (store) {
      throw new AssertionError("Must not store ObjectStreamClass instances with strong references to classes");
    } else if (ObjectStreamClass.lookup(forClass) == desc) {
      this.klazz = new WeakReference<>(forClass);
    }
  }
  this.hashCode = (3 * desc.getName().hashCode()) ^ (7 * (int) (desc.getSerialVersionUID() >>> 32))
      ^ (11 * (int) desc.getSerialVersionUID());
  this.osc = desc;
}
 
Example 10
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 11
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(
            Class.forName(Kosler_Agilent7700_RawDataTemplate.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of Kosler_Agilent7700_RawDataTemplate " + theSUID);
}
 
Example 12
Source Project: jdk8u60   File: SerialVer.java    License: GNU General Public License v2.0 5 votes vote down vote up
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 13
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 14
Source Project: flink   File: InstantiationUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
	ObjectStreamClass streamClassDescriptor = super.readClassDescriptor();

	try {
		Class.forName(streamClassDescriptor.getName(), false, classLoader);
	} catch (ClassNotFoundException e) {

		final ObjectStreamClass equivalentSerializer =
				MigrationUtil.getEquivalentSerializer(streamClassDescriptor.getName());

		if (equivalentSerializer != null) {
			return equivalentSerializer;
		}
	}

	final Class localClass = resolveClass(streamClassDescriptor);
	final String name = localClass.getName();
	if (scalaSerializerClassnames.contains(name) || scalaTypes.contains(name) || isAnonymousClass(localClass)
		|| isOldAvroSerializer(name, streamClassDescriptor.getSerialVersionUID())) {
		final ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
		if (localClassDescriptor != null
			&& localClassDescriptor.getSerialVersionUID() != streamClassDescriptor.getSerialVersionUID()) {
			LOG.warn("Ignoring serialVersionUID mismatch for class {}; was {}, now {}.",
				streamClassDescriptor.getName(), streamClassDescriptor.getSerialVersionUID(), localClassDescriptor.getSerialVersionUID());

			streamClassDescriptor = localClassDescriptor;
		}
	}

	return streamClassDescriptor;
}
 
Example 15
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(
            Class.forName(LevenbergMarquardGeneralSolverWithVecV.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of LevenbergMarquardGeneralSolverWithVecV " + theSUID);
}
 
Example 16
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(
            Class.forName(RittnerAgilent7700FileHandler.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of RittnerAgilent7700FileHandler " + theSUID);
}
 
Example 17
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 18
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(
            Class.forName(Rittner_Agilent7700_RawDataTemplate.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of Rittner_Agilent7700_RawDataTemplate " + theSUID);
}
 
Example 19
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 20
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}