public synchronized void write (Connection connection, ByteBuffer buffer, Object object) { output.setBuffer(buffer); kryo.getContext().put("connection", connection); kryo.writeClassAndObject(output, object); output.flush(); }
/** * Serializes given object to byte buffer using Kryo instance in pool. * * @param obj Object to serialize * @param buffer to write to */ public void serialize(final Object obj, final ByteBuffer buffer) { ByteBufferOutput out = new ByteBufferOutput(buffer); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** * Serializes given object to OutputStream using Kryo instance in pool. * * @param obj Object to serialize * @param stream to write to * @param bufferSize size of the buffer in front of the stream */ public void serialize(final Object obj, final OutputStream stream, final int bufferSize) { ByteBufferOutput out = new ByteBufferOutput(stream, bufferSize); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** Flushes any buffered bytes and closes the underlying OutputStream, if any. */ public void close () throws KryoException { flush(); if (outputStream != null) { try { outputStream.close(); } catch (IOException ignored) { } } }
/** Flushes any buffered bytes and closes the underlying OutputStream, if any. */ public void close () throws KryoException { flush(); if (outputStream != null) { try { outputStream.close(); } catch (IOException ignored) { } } }
/** Flushes any buffered bytes and closes the underlying OutputStream, if any. */ public void close () throws KryoException { flush(); if (outputStream != null) { try { outputStream.close(); } catch (IOException ignored) { } } }
/** Flushes any buffered bytes and closes the underlying OutputStream, if any. */ public void close () throws KryoException { flush(); if (outputStream != null) { try { outputStream.close(); } catch (IOException ignored) { } } }
/** @return true if the buffer has been resized. */ protected boolean require (int required) throws KryoException { if (capacity - position >= required) return false; if (required > maxCapacity) throw new KryoException("Buffer overflow. Max capacity: " + maxCapacity + ", required: " + required); flush(); while (capacity - position < required) { if (capacity == maxCapacity) throw new KryoException("Buffer overflow. Available: " + (capacity - position) + ", required: " + required); // Grow buffer. capacity = Math.min(capacity * 2, maxCapacity); if (capacity < 0) capacity = maxCapacity; ByteBuffer newBuffer = ByteBuffer.allocateDirect(capacity); // Copy the whole buffer niobuffer.position(0); newBuffer.put(niobuffer); newBuffer.order(byteOrder); niobuffer = newBuffer; } return true; }
/** @return true if the buffer has been resized. */ protected boolean require (int required) throws KryoException { if (capacity - position >= required) return false; if (required > maxCapacity) throw new KryoException("Buffer overflow. Max capacity: " + maxCapacity + ", required: " + required); flush(); while (capacity - position < required) { if (capacity == maxCapacity) throw new KryoException("Buffer overflow. Available: " + (capacity - position) + ", required: " + required); // Grow buffer. if (capacity == 0) capacity = 1; capacity = Math.min(capacity * 2, maxCapacity); if (capacity < 0) capacity = maxCapacity; ByteBuffer newBuffer = (niobuffer != null && !niobuffer.isDirect()) ? ByteBuffer.allocate(capacity) : ByteBuffer .allocateDirect(capacity); // Copy the whole buffer niobuffer.position(0); newBuffer.put(niobuffer); newBuffer.order(byteOrder); niobuffer = newBuffer; } return true; }
throw new KryoException("Buffer overflow. Max capacity: " + maxCapacity + ", required: " + required); flush(); while (capacity - position < required) { if (capacity == maxCapacity) {
throw new KryoException("Buffer overflow. Max capacity: " + maxCapacity + ", required: " + required); flush(); while (capacity - position < required) { if (capacity == maxCapacity) {
public synchronized void write (Connection connection, ByteBuffer buffer, Object object) { output.setBuffer(buffer); kryo.getContext().put("connection", connection); kryo.writeClassAndObject(output, object); output.flush(); }
/** * Serializes given object to byte buffer using Kryo instance in pool. * * @param obj Object to serialize * @param buffer to write to */ public void serialize(final Object obj, final ByteBuffer buffer) { ByteBufferOutput out = new ByteBufferOutput(buffer); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** * Serializes given object to byte buffer using Kryo instance in pool. * * @param obj Object to serialize * @param buffer to write to */ public void serialize(final Object obj, final ByteBuffer buffer) { ByteBufferOutput out = new ByteBufferOutput(buffer); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** * Serializes given object to OutputStream using Kryo instance in pool. * * @param obj Object to serialize * @param stream to write to * @param bufferSize size of the buffer in front of the stream */ public void serialize(final Object obj, final OutputStream stream, final int bufferSize) { ByteBufferOutput out = new ByteBufferOutput(stream, bufferSize); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** * Serializes given object to byte buffer using Kryo instance in pool. * * @param obj Object to serialize * @param buffer to write to */ public void serialize(final Object obj, final ByteBuffer buffer) { ByteBufferOutput out = new ByteBufferOutput(buffer); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** * Serializes given object to OutputStream using Kryo instance in pool. * * @param obj Object to serialize * @param stream to write to * @param bufferSize size of the buffer in front of the stream */ public void serialize(final Object obj, final OutputStream stream, final int bufferSize) { ByteBufferOutput out = new ByteBufferOutput(stream, bufferSize); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
/** * Serializes given object to OutputStream using Kryo instance in pool. * * @param obj Object to serialize * @param stream to write to * @param bufferSize size of the buffer in front of the stream */ public void serialize(final Object obj, final OutputStream stream, final int bufferSize) { ByteBufferOutput out = new ByteBufferOutput(stream, bufferSize); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }