List of usage examples for java.nio ByteBuffer position
public final int position()
From source file:com.alvermont.terraj.fracplanet.util.ByteBufferUtils.java
/** * The sizes of Java types are fixed and defined by the language spec so * this shouldn't be necessary but I'm going to do it anyway - so * there!/* w w w. j ava2 s . c om*/ * * @return The number of bytes occupied by an int value */ public static int sizeofInt() { final ByteBuffer buffer = ByteBuffer.allocate(10); buffer.putInt(0); return buffer.position(); }
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 a v a 2 s. c o m*/ byte[] b = new byte[buffer.remaining()]; buffer.get(b); digest.update(b); } }
From source file:com.alvermont.terraj.fracplanet.util.ByteBufferUtils.java
/** * The sizes of Java types are fixed and defined by the language spec so * this shouldn't be necessary but I'm going to do it anyway - so * there!//from www. j av a 2 s . c o m * * @return The number of bytes occupied by a float value */ public static int sizeofFloat() { final ByteBuffer buffer = ByteBuffer.allocate(10); buffer.putFloat(0.0f); return buffer.position(); }
From source file:Main.java
public static void toString(ByteBuffer bb, StringBuilder sb) { byte[] buf = bb.array(); int arrayOffset = bb.arrayOffset(); int offset = arrayOffset + bb.position(); int origLimit = arrayOffset + bb.limit(); int limit = (origLimit - offset > 128) ? offset + 128 : origLimit; for (int i = offset; i < limit; i++) { if (i > offset) { sb.append(" "); }//from ww w . jav a2 s. c o m sb.append(paddedByteString(buf[i])); } if (origLimit != limit) { sb.append("..."); } }
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.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:Main.java
private static byte[] byteBufferToArray(ByteBuffer bb) { byte[] bytes = new byte[bb.position()]; bb.rewind();//from w ww .ja v a 2 s .c o m bb.get(bytes, 0, bytes.length); return bytes; }
From source file:Main.java
public static int byteBufferToByteArray(ByteBuffer byteBuffer, byte[] target, int offset) { int remaining = byteBuffer.remaining(); System.arraycopy(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), target, offset, remaining);//from w w w . j a v a 2 s . c o m return remaining; }
From source file:com.icloud.framework.core.nio.ByteBufferUtil.java
public static int compare(byte[] o1, ByteBuffer o2) { return compareUnsigned(o1, o2.array(), 0, o2.arrayOffset() + o2.position(), o1.length, o2.limit() + o2.arrayOffset()); }
From source file:com.icloud.framework.core.nio.ByteBufferUtil.java
public static String string(ByteBuffer b, Charset charset) { return new String(b.array(), b.arrayOffset() + b.position(), b.remaining(), charset); }