Search in sources :

Example 16 with ObjectInputStream

use of java.io.ObjectInputStream in project mybatis-3 by mybatis.

the class UtilityTester method deserialzeObject.

private static Object deserialzeObject(byte[] aSerializedObject) {
    try {
        // Deserialize from a byte array
        ObjectInputStream myObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(aSerializedObject));
        Object myResult = myObjectInputStream.readObject();
        myObjectInputStream.close();
        return myResult;
    } catch (Exception anException) {
        throw new RuntimeException("Problem deserializing", anException);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 17 with ObjectInputStream

use of java.io.ObjectInputStream in project mybatis-3 by mybatis.

the class LazyDeserializeTest method deserializeFoo.

private LazyObjectFoo deserializeFoo(final byte[] serializedFoo) throws Exception {
    final ByteArrayInputStream bis = new ByteArrayInputStream(serializedFoo);
    final ObjectInputStream ios = new ObjectInputStream(bis);
    final LazyObjectFoo foo = LazyObjectFoo.class.cast(ios.readObject());
    ios.close();
    return foo;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 18 with ObjectInputStream

use of java.io.ObjectInputStream in project storm by nathanmarz.

the class Utils method deserialize.

public static Object deserialize(byte[] serialized) {
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
        ObjectInputStream ois = new ObjectInputStream(bis);
        Object ret = ois.readObject();
        ois.close();
        return ret;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentObject(backtype.storm.generated.ComponentObject) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 19 with ObjectInputStream

use of java.io.ObjectInputStream in project storm by nathanmarz.

the class SerializableSerializer method read.

@Override
public Object read(Kryo kryo, Input input, Class c) {
    int len = input.readInt();
    byte[] ser = new byte[len];
    input.readBytes(ser);
    ByteArrayInputStream bis = new ByteArrayInputStream(ser);
    try {
        ObjectInputStream ois = new ObjectInputStream(bis);
        return ois.readObject();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 20 with ObjectInputStream

use of java.io.ObjectInputStream in project jersey by jersey.

the class ReadWriteLockDataStore method deserialize.

/**
     * Deserializes an {@code Optional<Object>} from the given stream.
     * <p/>
     * The given stream will not be close.
     *
     * @param input the serialized object input stream, must not be null
     * @return the serialized object
     * @throws IOException in case the load operation failed
     **/
private static Optional<Object> deserialize(InputStream input) throws IOException {
    try {
        BufferedInputStream bis = new BufferedInputStream(input);
        ObjectInputStream ois = new ObjectInputStream(bis);
        return Optional.of(ois.readObject());
    } catch (ClassNotFoundException ex) {
        LOG.error("An error occurred during deserialization an object.", ex);
    }
    return Optional.empty();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)2159 ByteArrayInputStream (java.io.ByteArrayInputStream)1406 ObjectOutputStream (java.io.ObjectOutputStream)970 ByteArrayOutputStream (java.io.ByteArrayOutputStream)807 IOException (java.io.IOException)752 Test (org.junit.Test)458 FileInputStream (java.io.FileInputStream)339 File (java.io.File)197 InputStream (java.io.InputStream)157 ArrayList (java.util.ArrayList)90 BufferedInputStream (java.io.BufferedInputStream)84 Serializable (java.io.Serializable)66 FileNotFoundException (java.io.FileNotFoundException)64 FileOutputStream (java.io.FileOutputStream)63 HashMap (java.util.HashMap)63 Socket (java.net.Socket)49 Map (java.util.Map)48 ObjectInput (java.io.ObjectInput)45 GZIPInputStream (java.util.zip.GZIPInputStream)44 List (java.util.List)37