Search in sources :

Example 6 with KryoException

use of com.esotericsoftware.kryo.KryoException in project apex-core by apache.

the class Journal method setOutputStream.

public void setOutputStream(@Nullable final OutputStream out) throws IOException {
    final Output output;
    if (out != null) {
        output = new Output(4096, -1) {

            @Override
            public void flush() throws KryoException {
                super.flush();
                // Kryo does not flush internal output stream during flush. We need to flush it explicitly.
                try {
                    getOutputStream().flush();
                } catch (IOException e) {
                    throw new KryoException(e);
                }
            }
        };
        output.setOutputStream(out);
    } else {
        output = null;
    }
    final Output oldOut = this.output.getAndSet(output);
    if (oldOut != null && oldOut.getOutputStream() != out) {
        synchronized (oldOut) {
            oldOut.close();
        }
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) Output(com.esotericsoftware.kryo.io.Output) IOException(java.io.IOException)

Example 7 with KryoException

use of com.esotericsoftware.kryo.KryoException in project cas by apereo.

the class CasKryoTranscoderTests method verifyEncodeDecodeNonRegisteredClass.

@Test
public void verifyEncodeDecodeNonRegisteredClass() {
    final TicketGrantingTicket tgt = new MockTicketGrantingTicket(USERNAME);
    final MockServiceTicket expectedST = new MockServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), tgt);
    // This class is not registered with Kryo
    final UnregisteredServiceTicketExpirationPolicy step = new UnregisteredServiceTicketExpirationPolicy(1, 600);
    expectedST.setExpiration(step);
    try {
        transcoder.encode(expectedST);
        throw new AssertionError("Unregistered class is not allowed by Kryo");
    } catch (final KryoException e) {
    } catch (final Exception e) {
        throw new AssertionError("Unexpected exception due to not resetting Kryo between de-serializations with unregistered class.");
    }
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) KryoException(com.esotericsoftware.kryo.KryoException) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) KryoException(com.esotericsoftware.kryo.KryoException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) Test(org.junit.Test)

Example 8 with KryoException

use of com.esotericsoftware.kryo.KryoException in project apex-malhar by apache.

the class KryoJavaSerializer method read.

@Override
public Object read(Kryo kryo, Input input, Class type) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectInputStream objectStream = (ObjectInputStream) graphContext.get(this);
        if (objectStream == null) {
            objectStream = new ObjectInputStreamWithKryoClassLoader(input, kryo);
            graphContext.put(this, objectStream);
        }
        return objectStream.readObject();
    } catch (Exception ex) {
        throw new KryoException("Error during Java deserialization.", ex);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) ObjectMap(com.esotericsoftware.kryo.util.ObjectMap) IOException(java.io.IOException) KryoException(com.esotericsoftware.kryo.KryoException) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with KryoException

use of com.esotericsoftware.kryo.KryoException in project flink by apache.

the class NoFetchingInput method readBytes.

@Override
public void readBytes(byte[] bytes, int offset, int count) throws KryoException {
    if (bytes == null) {
        throw new IllegalArgumentException("bytes cannot be null.");
    }
    try {
        int bytesRead = 0;
        int c;
        while (true) {
            c = inputStream.read(bytes, offset + bytesRead, count - bytesRead);
            if (c == -1) {
                throw new KryoException(new EOFException("No more bytes left."));
            }
            bytesRead += c;
            if (bytesRead == count) {
                break;
            }
        }
    } catch (IOException ex) {
        throw new KryoException(ex);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) EOFException(java.io.EOFException) IOException(java.io.IOException)

Example 10 with KryoException

use of com.esotericsoftware.kryo.KryoException in project flink by apache.

the class JavaSerializer method read.

@SuppressWarnings("unchecked")
@Override
public T read(Kryo kryo, Input input, Class aClass) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectInputStream objectStream = (ObjectInputStream) graphContext.get(this);
        if (objectStream == null) {
            // make sure we use Kryo's classloader
            objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
            graphContext.put(this, objectStream);
        }
        return (T) objectStream.readObject();
    } catch (Exception ex) {
        throw new KryoException("Error during Java deserialization.", ex);
    }
}
Also used : InstantiationUtil(org.apache.flink.util.InstantiationUtil) KryoException(com.esotericsoftware.kryo.KryoException) ObjectMap(com.esotericsoftware.kryo.util.ObjectMap) KryoException(com.esotericsoftware.kryo.KryoException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

KryoException (com.esotericsoftware.kryo.KryoException)17 IOException (java.io.IOException)6 Output (com.esotericsoftware.kryo.io.Output)5 EOFException (java.io.EOFException)4 ObjectMap (com.esotericsoftware.kryo.util.ObjectMap)3 SerializationException (com.nokia.dempsy.serialization.SerializationException)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 CachedData (net.spy.memcached.CachedData)1 DataInputViewStream (org.apache.flink.api.java.typeutils.runtime.DataInputViewStream)1 DataOutputViewStream (org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream)1 NoFetchingInput (org.apache.flink.api.java.typeutils.runtime.NoFetchingInput)1 InstantiationUtil (org.apache.flink.util.InstantiationUtil)1