List of usage examples for java.nio ByteBuffer remaining
public final int remaining()
From source file:com.liveramp.cascading_ext.Bytes.java
/** * Always return a byte array that is a deep copy of the range represented * by the given ByteBuffer.// w w w. jav a 2 s .c o m * * @param byteBuffer * @return */ public static byte[] byteBufferDeepCopy(ByteBuffer byteBuffer) { byte[] target = new byte[byteBuffer.remaining()]; byteBufferToByteArray(byteBuffer, target, 0); return target; }
From source file:Main.java
public static byte[] byteBufferToByteArray(ByteBuffer byteBuffer) { if (wrapsFullArray(byteBuffer)) { return byteBuffer.array(); }/* w w w . j a v a2 s . c o m*/ byte[] target = new byte[byteBuffer.remaining()]; byteBufferToByteArray(byteBuffer, target, 0); return target; }
From source file:com.icloud.framework.core.nio.ByteBufferUtil.java
public static ByteBuffer clone(ByteBuffer o) { assert o != null; if (o.remaining() == 0) return ByteBuffer.wrap(ArrayUtils.EMPTY_BYTE_ARRAY); ByteBuffer clone = ByteBuffer.allocate(o.remaining()); if (o.isDirect()) { for (int i = o.position(); i < o.limit(); i++) { clone.put(o.get(i));/*from w w w .j a va 2 s . c om*/ } clone.flip(); } else { System.arraycopy(o.array(), o.arrayOffset() + o.position(), clone.array(), 0, o.remaining()); } return clone; }
From source file:net.sf.jml.util.DigestUtils.java
private static void update(MessageDigest digest, ByteBuffer buffer) { if (buffer.hasArray()) { digest.update(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else {//from w w w .j av a2s . c o m byte[] b = new byte[buffer.remaining()]; buffer.get(b); digest.update(b); } }
From source file:Main.java
public static final int indexOfP(final ByteBuffer bb, final byte b) { return indexOf(bb.array(), bb.position(), bb.remaining(), b); }
From source file:com.liveramp.commons.util.BytesUtils.java
public static int compareBytesUnsigned(ByteBuffer a, ByteBuffer b) { if (a.remaining() != b.remaining()) { throw new RuntimeException( "Cannot compare ByteBuffers that have a different number of remaining elements."); }/* w w w . j a v a 2 s . co m*/ return compareBytesUnsigned(a.array(), a.arrayOffset() + a.position(), b.array(), b.arrayOffset() + b.position(), a.remaining()); }
From source file:com.icloud.framework.core.nio.ByteBufferUtil.java
public static String string(ByteBuffer b) { return new String(b.array(), b.arrayOffset() + b.position(), b.remaining()); }
From source file:com.healthmarketscience.jackcess.impl.CustomToStringStyle.java
private static void appendDetail(StringBuffer buffer, ByteBuffer bb) { int len = bb.remaining(); buffer.append("(").append(len).append(") "); buffer.append(ByteUtil.toHexString(bb, bb.position(), Math.min(len, MAX_BYTE_DETAIL_LEN))); if (len > MAX_BYTE_DETAIL_LEN) { buffer.append(" ..."); }/*ww w . jav a 2s. co m*/ }
From source file:com.openteach.diamond.network.waverider.command.Command.java
/** * ByteBuffer??/*from www . ja v a2 s. co m*/ * @param buffer * @return */ public static Command unmarshall(ByteBuffer buffer) { if (buffer.remaining() < getHeaderSize()) { throw new RuntimeException("Wrong command."); } Command command = new Command(); command.setType(buffer.getLong()); command.setLength(buffer.getInt()); // (payLoad)array() command.setPayLoad(buffer.slice()); return command; }
From source file:com.liveramp.commons.util.BytesUtils.java
public static byte[] deepCopyByteBufferToByteArray(ByteBuffer byteBuffer) { byte[] result = new byte[byteBuffer.remaining()]; System.arraycopy(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), result, 0, byteBuffer.remaining());//from www. jav a 2s .co m return result; }