Search in sources :

Example 1 with MemoryOutputStream

use of org.apache.cassandra.io.util.MemoryOutputStream in project cassandra by apache.

the class SerializingCache method serialize.

private RefCountedMemory serialize(V value) {
    long serializedSize = serializer.serializedSize(value);
    if (serializedSize > Integer.MAX_VALUE)
        throw new IllegalArgumentException(String.format("Unable to allocate %s", FBUtilities.prettyPrintMemory(serializedSize)));
    RefCountedMemory freeableMemory;
    try {
        freeableMemory = new RefCountedMemory(serializedSize);
    } catch (OutOfMemoryError e) {
        return null;
    }
    try {
        serializer.serialize(value, new WrappedDataOutputStreamPlus(new MemoryOutputStream(freeableMemory)));
    } catch (IOException e) {
        freeableMemory.unreference();
        throw new RuntimeException(e);
    }
    return freeableMemory;
}
Also used : WrappedDataOutputStreamPlus(org.apache.cassandra.io.util.WrappedDataOutputStreamPlus) IOException(java.io.IOException) MemoryOutputStream(org.apache.cassandra.io.util.MemoryOutputStream)

Example 2 with MemoryOutputStream

use of org.apache.cassandra.io.util.MemoryOutputStream in project eiger by wlloyd.

the class SerializingCache method serialize.

private FreeableMemory serialize(V value) {
    long serializedSize = serializer.serializedSize(value);
    if (serializedSize > Integer.MAX_VALUE)
        throw new IllegalArgumentException("Unable to allocate " + serializedSize + " bytes");
    FreeableMemory freeableMemory;
    try {
        freeableMemory = new FreeableMemory(serializedSize);
    } catch (OutOfMemoryError e) {
        return null;
    }
    try {
        serializer.serialize(value, new DataOutputStream(new MemoryOutputStream(freeableMemory)));
    } catch (IOException e) {
        throw new IOError(e);
    }
    return freeableMemory;
}
Also used : IOError(java.io.IOError) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) MemoryOutputStream(org.apache.cassandra.io.util.MemoryOutputStream)

Aggregations

IOException (java.io.IOException)2 MemoryOutputStream (org.apache.cassandra.io.util.MemoryOutputStream)2 DataOutputStream (java.io.DataOutputStream)1 IOError (java.io.IOError)1 WrappedDataOutputStreamPlus (org.apache.cassandra.io.util.WrappedDataOutputStreamPlus)1