@Test public void cleanDirectBuffer() { final int MAX_ITERATIONS = 1024; final int BUFFER_SIZE = 16 * 1024 * 1024; ByteBuffer[] bufferArray = new ByteBuffer[MAX_ITERATIONS]; try { for (int i = 0; i < MAX_ITERATIONS; i++) { ByteBuffer buf = ByteBuffer.allocateDirect(BUFFER_SIZE); bufferArray[i] = buf; BufferUtils.cleanDirectBuffer(buf); } } catch (OutOfMemoryError ooe) { fail("cleanDirectBuffer is causing memory leak." + ooe.getMessage()); } }
public static synchronized void cleanDirectBuffer(ByteBuffer buffer) { Preconditions.checkNotNull(buffer, "buffer is null"); Preconditions.checkArgument(buffer.isDirect(), "buffer isn't a DirectByteBuffer"); int javaVersion = CommonUtils.getJavaVersion(); if (javaVersion < 9) { cleanDirectBufferJava8(buffer); } else { cleanDirectBufferJava11(buffer); } }
BufferUtils { public static synchronized void cleanDirectBuffer(ByteBuffer buffer) { Preconditions.checkNotNull(buffer, "buffer is null"); Preconditions.checkArgument(buffer.isDirect(), "buffer isn't a DirectByteBuffer"); int javaVersion = CommonUtils.getJavaVersion(); if (javaVersion < 9) { cleanDirectBufferJava8(buffer); } else { cleanDirectBufferJava11(buffer); } } }
BufferUtils { public static synchronized void cleanDirectBuffer(ByteBuffer buffer) { Preconditions.checkNotNull(buffer, "buffer is null"); Preconditions.checkArgument(buffer.isDirect(), "buffer isn't a DirectByteBuffer"); int javaVersion = CommonUtils.getJavaVersion(); if (javaVersion < 9) { cleanDirectBufferJava8(buffer); } else { cleanDirectBufferJava11(buffer); } } private  BufferUtils(); }
BufferUtils { public static synchronized void cleanDirectBuffer(ByteBuffer buffer) { Preconditions.checkNotNull(buffer, "buffer is null"); Preconditions.checkArgument(buffer.isDirect(), "buffer isn't a DirectByteBuffer"); int javaVersion = CommonUtils.getJavaVersion(); if (javaVersion < 9) { cleanDirectBufferJava8(buffer); } else { cleanDirectBufferJava11(buffer); } } private  BufferUtils(); static int byteToInt(byte b); static synchronized void cleanDirectBuffer(ByteBuffer buffer); static ByteBuffer cloneByteBuffer(ByteBuffer buf); static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source); static void putIntByteBuffer(ByteBuffer buf, int b); static byte[] getIncreasingByteArray(int len); static byte[] getIncreasingByteArray(int start, int len); static boolean equalConstantByteArray(byte value, int len, byte[] arr); static boolean equalIncreasingByteArray(int len, byte[] arr); static boolean equalIncreasingByteArray(int start, int len, byte[] arr); static ByteBuffer getIncreasingByteBuffer(int len); static ByteBuffer getIncreasingByteBuffer(int start, int len); static boolean equalIncreasingByteBuffer(int start, int len, ByteBuffer buf); static void writeBufferToFile(String path, byte[] buffer); static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest); static int intAsUnsignedByteValue(int i); static byte[] newByteArrayFromByteBuffer(ByteBuffer buf); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position, int length); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position); }
BufferUtils { public static synchronized void cleanDirectBuffer(ByteBuffer buffer) { Preconditions.checkNotNull(buffer, "buffer is null"); Preconditions.checkArgument(buffer.isDirect(), "buffer isn't a DirectByteBuffer"); int javaVersion = CommonUtils.getJavaVersion(); if (javaVersion < 9) { cleanDirectBufferJava8(buffer); } else { cleanDirectBufferJava11(buffer); } } private  BufferUtils(); static int byteToInt(byte b); static synchronized void cleanDirectBuffer(ByteBuffer buffer); static ByteBuffer cloneByteBuffer(ByteBuffer buf); static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source); static void putIntByteBuffer(ByteBuffer buf, int b); static byte[] getIncreasingByteArray(int len); static byte[] getIncreasingByteArray(int start, int len); static boolean equalConstantByteArray(byte value, int len, byte[] arr); static boolean equalIncreasingByteArray(int len, byte[] arr); static boolean equalIncreasingByteArray(int start, int len, byte[] arr); static ByteBuffer getIncreasingByteBuffer(int len); static ByteBuffer getIncreasingByteBuffer(int start, int len); static boolean equalIncreasingByteBuffer(int start, int len, ByteBuffer buf); static void writeBufferToFile(String path, byte[] buffer); static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest); static int intAsUnsignedByteValue(int i); static byte[] newByteArrayFromByteBuffer(ByteBuffer buf); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position, int length); static ByteBuffer sliceByteBuffer(ByteBuffer buffer, int position);  }