Search in sources :

Example 81 with ObjectInputStream

use of java.io.ObjectInputStream in project carat by amplab.

the class CaratDataStorage method readObject.

public Object readObject(String fname) {
    FileInputStream fin = getFin(fname);
    if (fin == null)
        return null;
    try {
        ObjectInputStream din = new ObjectInputStream(fin);
        Object o = din.readObject();
        din.close();
        return o;
    } catch (IOException e) {
        Log.e(this.getClass().getName(), "Could not read object from " + fname + "!");
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        Log.e(this.getClass().getName(), "Could not find class: " + e.getMessage() + " reading from " + fname + "!");
        e.printStackTrace();
    } catch (Throwable th) {
        Log.e(this.getClass().getName(), "Problem reading object", th);
    }
    return null;
}
Also used : IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 82 with ObjectInputStream

use of java.io.ObjectInputStream in project camel by apache.

the class RabbitMQMessageConverter method deserializeBody.

private void deserializeBody(final Exchange camelExchange, final Message message, final byte[] body) {
    Object messageBody = null;
    try (InputStream b = new ByteArrayInputStream(body);
        ObjectInputStream o = new ObjectInputStream(b)) {
        messageBody = o.readObject();
    } catch (IOException | ClassNotFoundException e) {
        LOG.warn("Could not deserialize the object");
        camelExchange.setException(e);
    }
    if (messageBody instanceof Throwable) {
        LOG.debug("Reply was an Exception. Setting the Exception on the Exchange");
        camelExchange.setException((Throwable) messageBody);
    } else {
        message.setBody(messageBody);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 83 with ObjectInputStream

use of java.io.ObjectInputStream in project jstorm by alibaba.

the class AutoTGT method getTGT.

public static KerberosTicket getTGT(Map<String, String> credentials) {
    KerberosTicket ret = null;
    if (credentials != null && credentials.containsKey("TGT")) {
        try {
            ByteArrayInputStream bin = new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(credentials.get("TGT")));
            ObjectInputStream in = new ObjectInputStream(bin);
            ret = (KerberosTicket) in.readObject();
            in.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return ret;
}
Also used : KerberosTicket(javax.security.auth.kerberos.KerberosTicket) ByteArrayInputStream(java.io.ByteArrayInputStream) LoginException(javax.security.auth.login.LoginException) DestroyFailedException(javax.security.auth.DestroyFailedException) RefreshFailedException(javax.security.auth.RefreshFailedException) ObjectInputStream(java.io.ObjectInputStream)

Example 84 with ObjectInputStream

use of java.io.ObjectInputStream in project flink by apache.

the class FileSerializableStateHandle method getState.

@Override
@SuppressWarnings("unchecked")
public T getState(ClassLoader classLoader) throws Exception {
    ensureNotClosed();
    try (FSDataInputStream inStream = getFileSystem().open(getFilePath())) {
        // make sure any deserialization can be aborted
        registerCloseable(inStream);
        ObjectInputStream ois = new MigrationInstantiationUtil.ClassLoaderObjectInputStream(inStream, classLoader);
        return (T) ois.readObject();
    }
}
Also used : FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 85 with ObjectInputStream

use of java.io.ObjectInputStream in project flink by apache.

the class KeyedOneInputStreamOperatorTestHarness method restore.

/**
	 *
	 */
@Override
public void restore(StreamStateHandle snapshot) throws Exception {
    try (FSDataInputStream inStream = snapshot.openInputStream()) {
        if (operator instanceof StreamCheckpointedOperator) {
            ((StreamCheckpointedOperator) operator).restoreState(inStream);
        }
        byte keyedStatePresent = (byte) inStream.read();
        if (keyedStatePresent == 1) {
            ObjectInputStream ois = new ObjectInputStream(inStream);
            this.restoredKeyedState = Collections.singletonList((KeyGroupsStateHandle) ois.readObject());
        }
    }
}
Also used : FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) StreamCheckpointedOperator(org.apache.flink.streaming.api.operators.StreamCheckpointedOperator) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)1041 ByteArrayInputStream (java.io.ByteArrayInputStream)667 ObjectOutputStream (java.io.ObjectOutputStream)427 ByteArrayOutputStream (java.io.ByteArrayOutputStream)354 IOException (java.io.IOException)341 FileInputStream (java.io.FileInputStream)152 Test (org.junit.Test)128 File (java.io.File)89 InputStream (java.io.InputStream)85 BufferedInputStream (java.io.BufferedInputStream)47 Serializable (java.io.Serializable)40 HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)31 FileNotFoundException (java.io.FileNotFoundException)27 FileOutputStream (java.io.FileOutputStream)27 Test (org.testng.annotations.Test)26 Map (java.util.Map)25 EOFException (java.io.EOFException)21 GZIPInputStream (java.util.zip.GZIPInputStream)21 ObjectInput (java.io.ObjectInput)20