public static void clearOutput(Output output) { output.clear(); // 防止hold过大的内存块一直不释放 byte[] bytes = output.getBuffer(); if (bytes == null) { return; } if (bytes.length > MAX_CACHED_BUF_SIZE) { output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1); } }
public static void clearOutput(Output output) { output.clear(); // 防止hold过大的内存块一直不释放 byte[] bytes = output.getBuffer(); if (bytes == null) { return; } if (bytes.length > MAX_CACHED_BUF_SIZE) { output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1); } }
/** Sets the buffer that will be written to. {@link #setBuffer(byte[], int)} is called with the specified buffer's length as * the maxBufferSize. */ public void setBuffer (byte[] buffer) { setBuffer(buffer, buffer.length); }
/** Sets the buffer that will be written to. {@link #setBuffer(byte[], int)} is called with the specified buffer's length as * the maxBufferSize. */ public void setBuffer (byte[] buffer) { setBuffer(buffer, buffer.length); }
/** Sets the buffer that will be written to. {@link #setBuffer(byte[], int)} is called with the specified buffer's length as the * maxBufferSize. */ public void setBuffer (byte[] buffer) { setBuffer(buffer, buffer.length); }
/** Sets the buffer that will be written to. {@link #setBuffer(byte[], int)} is called with the specified buffer's length as the * maxBufferSize. */ public void setBuffer (byte[] buffer) { setBuffer(buffer, buffer.length); }
/** Creates a new Output for writing to a byte array. * @see #setBuffer(byte[], int) */ public Output (byte[] buffer, int maxBufferSize) { if (buffer == null) throw new IllegalArgumentException("buffer cannot be null."); setBuffer(buffer, maxBufferSize); }
/** Creates a new Output for writing to a byte array. * @see #setBuffer(byte[], int) */ public Output (byte[] buffer, int maxBufferSize) { if (buffer == null) throw new IllegalArgumentException("buffer cannot be null."); setBuffer(buffer, maxBufferSize); }
/** Creates a new Output for writing to a byte array. * @see #setBuffer(byte[], int) */ public Output (byte[] buffer, int maxBufferSize) { if (buffer == null) throw new IllegalArgumentException("buffer cannot be null."); setBuffer(buffer, maxBufferSize); }
/** Creates a new Output for writing to a byte array. * @see #setBuffer(byte[], int) */ public Output (byte[] buffer, int maxBufferSize) { if (buffer == null) throw new IllegalArgumentException("buffer cannot be null."); setBuffer(buffer, maxBufferSize); }
public KryoStreamSerializer(int outputBufferSize) { kryo = new Kryo(); kryo.setReferences(false); kryo.setRegistrationRequired(true); writeBuffer = new byte[outputBufferSize]; output = new Output(); output.setBuffer(writeBuffer); }
public static void clearOutput(Output output) { output.clear(); // 防止hold过大的内存块一直不释放 byte[] bytes = output.getBuffer(); if (bytes == null) { return; } if (bytes.length > MAX_CACHED_BUF_SIZE) { output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1); } }
public static void clearOutput(Output output) { output.clear(); // 防止hold过大的内存块一直不释放 byte[] bytes = output.getBuffer(); if (bytes == null) { return; } if (bytes.length > MAX_CACHED_BUF_SIZE) { output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1); } }
@Override public void close() { output.close(); input.close(); input.setBuffer(park); // clean input output.setBuffer(park, Integer.MAX_VALUE); // clear output kryopool.offer(this); } }
@Override public <T> void serialize(final T object, final MessageBufferOutput buffer) throws IOException { try (Holder k = getKryoHolder()) { final Output output = k.output; // this will allow kryo to grow the buffer as needed. output.setBuffer(buffer.getBuffer(), Integer.MAX_VALUE); output.setPosition(buffer.getPosition()); // set the position to where we already are. kryoRunner.doSerialize(k, output, object); // if we resized then we need to adjust the message buffer if (output.getBuffer() != buffer.getBuffer()) buffer.replace(output.getBuffer()); buffer.setPosition(output.position()); } catch (final KryoException ke) { throw new IOException("Failed to serialize.", ke); } catch (final IllegalArgumentException e) { // this happens when requiring registration but serializing an unregistered class throw new IOException("Failed to serialize " + objectDescription(object) + " (did you require registration and attempt to serialize an unregistered class?)", e); } }