@Test void testToInt() { ByteBuffer[] buf = { BufferUtils.toBuffer("0"), BufferUtils.toBuffer(" 42 "), BufferUtils.toBuffer(" 43abc"), BufferUtils.toBuffer("-44"), BufferUtils.toBuffer(" - 45;"), BufferUtils.toBuffer("-2147483648"), BufferUtils.toBuffer("2147483647"), }; int[] val = { 0, 42, 43, -44, -45, -2147483648, 2147483647 }; for (int i = 0; i < buf.length; i++) assertEquals(val[i], BufferUtils.toInt(buf[i]), "t" + i); }
public static int toInt(ByteBuffer buffer) { return toInt(buffer, buffer.position(), buffer.remaining()); }
BufferUtils { public static int toInt(ByteBuffer buffer) { return toInt(buffer, buffer.position(), buffer.remaining()); } }
BufferUtils { public static int toInt(ByteBuffer buffer) { return toInt(buffer, buffer.position(), buffer.remaining()); }  }
BufferUtils { public static int toInt(ByteBuffer buffer) { return toInt(buffer, buffer.position(), buffer.remaining()); }  static ByteBuffer allocate(int capacity); static ByteBuffer allocateDirect(int capacity); static void clear(ByteBuffer buffer); static void clearToFill(ByteBuffer buffer); static int flipToFill(ByteBuffer buffer); static void flipToFlush(ByteBuffer buffer, int position); static byte[] toArray(ByteBuffer buffer); static byte[] toArray(Collection<ByteBuffer> buffers); static boolean isTheEmptyBuffer(ByteBuffer buf); static boolean isEmpty(ByteBuffer buf); static boolean hasContent(ByteBuffer buf); static boolean isFull(ByteBuffer buf); static int length(ByteBuffer buffer); static int space(ByteBuffer buffer); static boolean compact(ByteBuffer buffer); static int put(ByteBuffer from, ByteBuffer to); static int flipPutFlip(ByteBuffer from, ByteBuffer to); static void append(ByteBuffer to, byte[] b, int off, int len); static void append(ByteBuffer to, byte b); static int append(ByteBuffer to, ByteBuffer b); static int fill(ByteBuffer to, byte[] b, int off, int len); static void readFrom(File file, ByteBuffer buffer); static void readFrom(InputStream is, int needed, ByteBuffer buffer); static void writeTo(ByteBuffer buffer, OutputStream out); static String toString(ByteBuffer buffer); static String toUTF8String(ByteBuffer buffer); static String toString(ByteBuffer buffer, Charset charset); static String toString(List<ByteBuffer> buffers, Charset charset); static String toString(ByteBuffer buffer, int position, int length, Charset charset); static int toInt(ByteBuffer buffer); static int toInt(ByteBuffer buffer, int position, int length); static int takeInt(ByteBuffer buffer); static long toLong(ByteBuffer buffer); static void putHexInt(ByteBuffer buffer, int n); static void putDecInt(ByteBuffer buffer, int n); static void putDecLong(ByteBuffer buffer, long n); static ByteBuffer toBuffer(int value); static ByteBuffer toBuffer(long value); static ByteBuffer toBuffer(String s); static ByteBuffer toBuffer(String s, Charset charset); static ByteBuffer toBuffer(byte[] array); static ByteBuffer toBuffer(byte[] array, int offset, int length); static ByteBuffer toDirectBuffer(String s); static ByteBuffer toDirectBuffer(String s, Charset charset); static ByteBuffer toMappedBuffer(File file); @Deprecated static boolean isMappedBuffer(ByteBuffer buffer); static String toSummaryString(ByteBuffer buffer); static String toDetailString(ByteBuffer[] buffer); static String toIDString(ByteBuffer buffer); static String toDetailString(ByteBuffer buffer); static String toHexSummary(ByteBuffer buffer); static String toHexString(ByteBuffer buffer); static void putCRLF(ByteBuffer buffer); static boolean isPrefix(ByteBuffer prefix, ByteBuffer buffer); static ByteBuffer ensureCapacity(ByteBuffer buffer, int capacity); static ByteBuffer addCapacity(ByteBuffer buffer, int capacity); static ByteBuffer merge(List<ByteBuffer> buffers); }
BufferUtils { public static int toInt(ByteBuffer buffer) { return toInt(buffer, buffer.position(), buffer.remaining()); }  static ByteBuffer allocate(int capacity); static ByteBuffer allocateDirect(int capacity); static void clear(ByteBuffer buffer); static void clearToFill(ByteBuffer buffer); static int flipToFill(ByteBuffer buffer); static void flipToFlush(ByteBuffer buffer, int position); static byte[] toArray(ByteBuffer buffer); static byte[] toArray(Collection<ByteBuffer> buffers); static boolean isTheEmptyBuffer(ByteBuffer buf); static boolean isEmpty(ByteBuffer buf); static boolean hasContent(ByteBuffer buf); static boolean isFull(ByteBuffer buf); static int length(ByteBuffer buffer); static int space(ByteBuffer buffer); static boolean compact(ByteBuffer buffer); static int put(ByteBuffer from, ByteBuffer to); static int flipPutFlip(ByteBuffer from, ByteBuffer to); static void append(ByteBuffer to, byte[] b, int off, int len); static void append(ByteBuffer to, byte b); static int append(ByteBuffer to, ByteBuffer b); static int fill(ByteBuffer to, byte[] b, int off, int len); static void readFrom(File file, ByteBuffer buffer); static void readFrom(InputStream is, int needed, ByteBuffer buffer); static void writeTo(ByteBuffer buffer, OutputStream out); static String toString(ByteBuffer buffer); static String toUTF8String(ByteBuffer buffer); static String toString(ByteBuffer buffer, Charset charset); static String toString(List<ByteBuffer> buffers, Charset charset); static String toString(ByteBuffer buffer, int position, int length, Charset charset); static int toInt(ByteBuffer buffer); static int toInt(ByteBuffer buffer, int position, int length); static int takeInt(ByteBuffer buffer); static long toLong(ByteBuffer buffer); static void putHexInt(ByteBuffer buffer, int n); static void putDecInt(ByteBuffer buffer, int n); static void putDecLong(ByteBuffer buffer, long n); static ByteBuffer toBuffer(int value); static ByteBuffer toBuffer(long value); static ByteBuffer toBuffer(String s); static ByteBuffer toBuffer(String s, Charset charset); static ByteBuffer toBuffer(byte[] array); static ByteBuffer toBuffer(byte[] array, int offset, int length); static ByteBuffer toDirectBuffer(String s); static ByteBuffer toDirectBuffer(String s, Charset charset); static ByteBuffer toMappedBuffer(File file); @Deprecated static boolean isMappedBuffer(ByteBuffer buffer); static String toSummaryString(ByteBuffer buffer); static String toDetailString(ByteBuffer[] buffer); static String toIDString(ByteBuffer buffer); static String toDetailString(ByteBuffer buffer); static String toHexSummary(ByteBuffer buffer); static String toHexString(ByteBuffer buffer); static void putCRLF(ByteBuffer buffer); static boolean isPrefix(ByteBuffer prefix, ByteBuffer buffer); static ByteBuffer ensureCapacity(ByteBuffer buffer, int capacity); static ByteBuffer addCapacity(ByteBuffer buffer, int capacity); static ByteBuffer merge(List<ByteBuffer> buffers); static final ByteBuffer EMPTY_BUFFER; }