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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations