Search in sources :

Example 1 with KryoException

use of com.esotericsoftware.kryo.KryoException in project Paper by pilgr.

the class DbStoragePlainFile method readTableFile.

private <E> E readTableFile(String key, File originalFile, boolean v1CompatibilityMode) {
    try {
        final Input i = new Input(new FileInputStream(originalFile));
        final Kryo kryo = getKryo();
        if (v1CompatibilityMode) {
            // Set temporary generic optimization to support Kryo 3.x format
            kryo.getFieldSerializerConfig().setOptimizedGenerics(true);
        }
        //noinspection unchecked
        final PaperTable<E> paperTable = kryo.readObject(i, PaperTable.class);
        i.close();
        if (v1CompatibilityMode) {
            kryo.getFieldSerializerConfig().setOptimizedGenerics(false);
        }
        return paperTable.mContent;
    } catch (FileNotFoundException | KryoException | ClassCastException e) {
        // Give one more chance, reread data in compatibility mode
        if (!v1CompatibilityMode) {
            return readTableFile(key, originalFile, true);
        }
        // Clean up an unsuccessfully written file
        if (originalFile.exists()) {
            if (!originalFile.delete()) {
                throw new PaperDbException("Couldn't clean up broken/unserializable file " + originalFile, e);
            }
        }
        String errorMessage = "Couldn't read/deserialize file " + originalFile + " for table " + key;
        throw new PaperDbException(errorMessage, e);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) KryoException(com.esotericsoftware.kryo.KryoException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 2 with KryoException

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

the class JavaSerializer method write.

@SuppressWarnings("unchecked")
@Override
public void write(Kryo kryo, Output output, T o) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectOutputStream objectStream = (ObjectOutputStream) graphContext.get(this);
        if (objectStream == null) {
            objectStream = new ObjectOutputStream(output);
            graphContext.put(this, objectStream);
        }
        objectStream.writeObject(o);
        objectStream.flush();
    } catch (Exception ex) {
        throw new KryoException("Error during Java serialization.", ex);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) ObjectMap(com.esotericsoftware.kryo.util.ObjectMap) ObjectOutputStream(java.io.ObjectOutputStream) KryoException(com.esotericsoftware.kryo.KryoException)

Example 3 with KryoException

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

the class NoFetchingInput method require.

/**
	 * Require makes sure that at least required number of bytes are kept in the buffer. If not, then
	 * it will load exactly the difference between required and currently available number of bytes.
	 * Thus, it will only load the data which is required and never prefetch data.
	 *
	 * @param required the number of bytes being available in the buffer
	 * @return the number of bytes remaining, which is equal to required
	 * @throws KryoException
	 */
@Override
protected int require(int required) throws KryoException {
    if (required > capacity) {
        throw new KryoException("Buffer too small: capacity: " + capacity + ", " + "required: " + required);
    }
    position = 0;
    int bytesRead = 0;
    int count;
    while (true) {
        count = fill(buffer, bytesRead, required - bytesRead);
        if (count == -1) {
            throw new KryoException(new EOFException("No more bytes left."));
        }
        bytesRead += count;
        if (bytesRead == required) {
            break;
        }
    }
    limit = required;
    return required;
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) EOFException(java.io.EOFException)

Example 4 with KryoException

use of com.esotericsoftware.kryo.KryoException in project Dempsy by Dempsy.

the class KryoSerializer method deserialize.

@SuppressWarnings("unchecked")
@Override
public T deserialize(byte[] data) throws SerializationException {
    KryoHolder k = null;
    try {
        k = getKryoHolder();
        k.input.setBuffer(data);
        return (T) (k.kryo.readClassAndObject(k.input));
    } catch (KryoException ke) {
        throw new SerializationException("Failed to deserialize.", ke);
    } catch (// this happens when requiring registration but deserializing an unregistered class
    IllegalArgumentException e) {
        throw new SerializationException("Failed to deserialize. Did you require registration and attempt to deserialize an unregistered class?", e);
    } finally {
        if (k != null)
            kryopool.offer(k);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) SerializationException(com.nokia.dempsy.serialization.SerializationException)

Example 5 with KryoException

use of com.esotericsoftware.kryo.KryoException in project Dempsy by Dempsy.

the class KryoSerializer method serialize.

@Override
public byte[] serialize(T object) throws SerializationException {
    KryoHolder k = null;
    try {
        k = getKryoHolder();
        k.output.clear();
        k.kryo.writeClassAndObject(k.output, object);
        return k.output.toBytes();
    } catch (KryoException ke) {
        throw new SerializationException("Failed to serialize.", ke);
    } catch (// this happens when requiring registration but serializing an unregistered class
    IllegalArgumentException e) {
        throw new SerializationException("Failed to serialize " + SafeString.objectDescription(object) + " (did you require registration and attempt to serialize an unregistered class?)", e);
    } finally {
        if (k != null)
            kryopool.offer(k);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) SerializationException(com.nokia.dempsy.serialization.SerializationException)

Aggregations

KryoException (com.esotericsoftware.kryo.KryoException)14 IOException (java.io.IOException)5 Output (com.esotericsoftware.kryo.io.Output)4 EOFException (java.io.EOFException)4 ObjectMap (com.esotericsoftware.kryo.util.ObjectMap)2 SerializationException (com.nokia.dempsy.serialization.SerializationException)2 ObjectOutputStream (java.io.ObjectOutputStream)2 Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)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 HybridHashTableContainer (org.apache.hadoop.hive.ql.exec.persistence.HybridHashTableContainer)1 HashPartition (org.apache.hadoop.hive.ql.exec.persistence.HybridHashTableContainer.HashPartition)1 MapJoinTableContainer (org.apache.hadoop.hive.ql.exec.persistence.MapJoinTableContainer)1