KryoSerializers { public static byte[] getBuffer(int capacity) { if (capacity > THREAD_LOCAL_BUFFER_LIMIT_BYTES) { return new byte[capacity]; } byte[] buffer = bufferPerThread.get(); if (buffer.length < capacity || buffer.length > capacity * 10) { buffer = new byte[capacity]; bufferPerThread.set(buffer); } return buffer; } private  KryoSerializers(); static Kryo create(boolean isObjectSerializer); static void register(ThreadLocal<Kryo> kryoThreadLocal, boolean isDocumentSerializer); static Output serializeDocument(ServiceDocument o, int maxSize); static Output serializeAsDocument(Object o, int maxSize); static Output serializeDocumentForIndexing(Object o, int maxSize); static int serializeObject(Object o, byte[] buffer, int position); static ByteBuffer serializeObject(Object o, int maxSize); static T clone(T t); static T cloneObject(T t); static byte[] getBuffer(int capacity); static Object deserializeObject(ByteBuffer bb); static Object deserializeObject(byte[] bytes, int position, int length); static Object deserializeDocument(byte[] bytes, int position, int length); static Object deserializeDocument(ByteBuffer bb); static final long THREAD_LOCAL_BUFFER_LIMIT_BYTES; }
@Test public void getBuffer() { byte[] existing = KryoSerializers.getBuffer(1024); int size = existing.length * 41; byte[] b = KryoSerializers.getBuffer(size); assertEquals(size, b.length); byte[] bSame = KryoSerializers.getBuffer(size); assertTrue(b.hashCode() == bSame.hashCode()); byte[] bLarger = KryoSerializers.getBuffer(size * 2); assertTrue(b.hashCode() != bLarger.hashCode()); byte[] veryLarge = KryoSerializers .getBuffer((int) KryoSerializers.THREAD_LOCAL_BUFFER_LIMIT_BYTES * 2); byte[] veryLargeSecond = KryoSerializers .getBuffer((int) KryoSerializers.THREAD_LOCAL_BUFFER_LIMIT_BYTES * 2); assertTrue(veryLarge.hashCode() != veryLargeSecond.hashCode()); }