List of usage examples for java.nio ByteBuffer limit
public final int limit()
From source file:Main.java
public final static byte[] toBytes(final ByteBuffer bb) { return toBytes(bb, bb.limit()); }
From source file:Main.java
private static byte[] encode(String text, Charset charset) { ByteBuffer buffer = charset.encode(text); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes);/*from w ww.j a va 2 s . co m*/ return bytes; }
From source file:Main.java
private static String getString(ByteBuffer buffer) { StringBuilder sb = new StringBuilder(buffer.limit()); while (buffer.remaining() > 0) { char c = (char) buffer.get(); if (c == 0) break; sb.append(c);// w ww . j a v a 2 s .co m } return sb.toString(); }
From source file:Main.java
public final static int copy(final ByteBuffer from, final ByteBuffer to) { final int len = from.limit(); return copy(from, 0, to, 0, len); }
From source file:Main.java
public static ByteBuffer createByteBufferOnHeap(ByteBuffer buf, final int size) { if (buf != null && buf.limit() == size) { buf.rewind();/*from w w w. ja v a2 s.co m*/ return buf; } buf = createByteBufferOnHeap(size); return buf; }
From source file:Main.java
public static byte[] computeSHA1(ByteBuffer convertme) { return computeSHA1(convertme, 0, convertme.limit()); }
From source file:Main.java
/** * position is 0 and limit = capacity.// w w w. j av a2s.c o m * * @param bb * @return */ public final static boolean isEmpty(final ByteBuffer bb) { return (bb.position() == 0 && bb.limit() == bb.capacity()) || bb.limit() == 0; }
From source file:Main.java
public static final ByteBuffer wrap(final ByteBuffer bb) { return (ByteBuffer) ByteBuffer.wrap(bb.array()).limit(bb.limit()).position(bb.position()); }
From source file:Main.java
public static ByteBuffer createByteBuffer(ByteBuffer buf, final int size) { if (buf != null && buf.limit() == size) { buf.rewind();//from w ww .j ava 2 s . com return buf; } buf = createByteBuffer(size); return buf; }
From source file:Main.java
private static byte[] getByteArrayFromBuffer(ByteBuffer byteBuf) { byteBuf.flip();/*from w ww. ja v a 2s. co m*/ byte[] row = new byte[byteBuf.limit()]; byteBuf.get(row); byteBuf.clear(); return row; }