Search in sources :

Example 21 with ObjectInputStream

use of java.io.ObjectInputStream in project lucida by claritylab.

the class ScoreNormalizationFilter method readSerializedResults.

/**
	 * Reads serialized results from a file.
	 * 
	 * @param input input file
	 * @return result objects
	 */
private static Result[] readSerializedResults(File input) {
    ArrayList<Result> results = new ArrayList<Result>();
    try {
        FileInputStream fis = new FileInputStream(input);
        ObjectInputStream ois = new ObjectInputStream(fis);
        // then discard it
        if (!(ois.readObject() instanceof AnalyzedQuestion)) {
            MsgPrinter.printErrorMsg("First serialized object is not an" + "AnalyzedQuestion.");
            System.exit(1);
        }
        try {
            while (true) results.add((Result) ois.readObject());
        } catch (EOFException e) {
        /* end of file reached */
        }
        ois.close();
    } catch (Exception e) {
        MsgPrinter.printErrorMsg("Could not read serialized results:");
        MsgPrinter.printErrorMsg(e.toString());
        System.exit(1);
    }
    return results.toArray(new Result[results.size()]);
}
Also used : ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) AnalyzedQuestion(info.ephyra.questionanalysis.AnalyzedQuestion) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException) Result(info.ephyra.search.Result) ObjectInputStream(java.io.ObjectInputStream)

Example 22 with ObjectInputStream

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

the class MemberIsUnavailableTest method deserialize.

private static MemberIsUnavailable deserialize(byte[] serialized) throws Exception {
    ObjectInputStream inputStream = null;
    try {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serialized);
        inputStream = new ObjectStreamFactory().create(byteArrayInputStream);
        return (MemberIsUnavailable) inputStream.readObject();
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) ObjectInputStream(java.io.ObjectInputStream)

Example 23 with ObjectInputStream

use of java.io.ObjectInputStream in project zipkin by openzipkin.

the class SpanTest method serialization.

@Test
public void serialization() throws Exception {
    Span span = TestObjects.TRACE.get(0);
    Buffer buffer = new Buffer();
    new ObjectOutputStream(buffer.outputStream()).writeObject(span);
    assertThat(new ObjectInputStream(buffer.inputStream()).readObject()).isEqualTo(span);
}
Also used : Buffer(okio.Buffer) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 24 with ObjectInputStream

use of java.io.ObjectInputStream in project jodd by oblac.

the class ObjectUtil method readObject.

/**
	 * Reads serialized object from the file.
	 */
public static Object readObject(File source) throws IOException, ClassNotFoundException {
    Object result = null;
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    ObjectInputStream ois = null;
    try {
        fis = new FileInputStream(source);
        bis = new BufferedInputStream(fis);
        ois = new ObjectInputStream(bis);
        result = ois.readObject();
    } finally {
        StreamUtil.close(ois);
        StreamUtil.close(bis);
        StreamUtil.close(fis);
    }
    return result;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 25 with ObjectInputStream

use of java.io.ObjectInputStream in project jodd by oblac.

the class ObjectUtil method byteArrayToObject.

/**
	 * De-serialize an object from byte array.
	 */
public static Object byteArrayToObject(byte[] data) throws IOException, ClassNotFoundException {
    Object retObj = null;
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(bais);
        retObj = ois.readObject();
    } finally {
        StreamUtil.close(ois);
    }
    return retObj;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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