List of usage examples for java.nio ByteBuffer position
public final int position()
From source file:Main.java
public final static int countP(final ByteBuffer bb, final byte[] text) { final int endIdx = bb.limit(); final byte[] array = bb.array(); return count(array, bb.position(), endIdx, text, 0, text.length); }
From source file:Main.java
public final static int countP(final ByteBuffer bb1, final ByteBuffer bb2) { final int end1 = bb1.limit(); final int end2 = bb2.limit(); final int offset1 = bb1.position(); final int offset2 = bb2.position(); final byte[] array1 = bb1.array(); final byte[] array2 = bb2.array(); return count(array1, offset1, end1, array2, offset2, end2); }
From source file:com.icloud.framework.core.nio.ByteBufferUtil.java
public static int compare(ByteBuffer o1, byte[] o2) { return compareUnsigned(o1.array(), o2, o1.arrayOffset() + o1.position(), 0, o1.limit() + o1.arrayOffset(), o2.length);//from w ww .ja v a 2s. c o m }
From source file:com.tera.common.util.ConsolePrinter.java
/** * Gets last <tt>cnt</tt> read bytes from the <tt>data</tt> buffer and puts * into <tt>result</tt> buffer in special format: * <ul>//from w w w. j a va 2 s . c o m * <li>if byte represents char from partition 0x1F to 0x80 (which are normal * ascii chars) then it's put into buffer as it is</li> * <li>otherwise dot is put into buffer</li> * </ul> * * @param data * @param result * @param cnt */ private static void toText(ByteBuffer data, StringBuilder result, int cnt) { int charPos = data.position() - cnt; for (int a = 0; a < cnt; a++) { int c = data.get(charPos++); if (c > 0x1f && c < 0x80) result.append((char) c); else result.append('.'); } }
From source file:Main.java
public final static boolean equalsP(final ByteBuffer bb1, final ByteBuffer bb2) { final byte[] array1 = bb1.array(); final byte[] array2 = bb2.array(); final int offset1 = bb1.position(); final int offset2 = bb2.position(); final int end1 = bb1.limit(); final int end2 = bb2.limit(); return equals(array1, offset1, end1, array2, offset2, end2); }
From source file:com.icloud.framework.core.nio.ByteBufferUtil.java
public static int compareUnsigned(ByteBuffer o1, ByteBuffer o2) { return compareUnsigned(o1.array(), o2.array(), o1.arrayOffset() + o1.position(), o2.arrayOffset() + o2.position(), o1.limit() + o1.arrayOffset(), o2.limit() + o2.arrayOffset()); }
From source file:com.bconomy.autobit.Encryption.java
private static byte[] charsToBytes(char[] chars) { CharBuffer charBuffer = CharBuffer.wrap(chars); ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer); byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data Arrays.fill(chars, '\u0000'); // clear sensitive data return bytes; }
From source file:Main.java
public static final int indexOfP(final ByteBuffer lineBB, final byte[][] textsLower, final byte[][] textsUpper) { return indexOf(lineBB.array(), lineBB.position(), lineBB.limit(), textsLower, textsUpper); }
From source file:com.oneguy.recognize.Util.java
public static ByteBuffer doubleSize(ByteBuffer buffer) { if (buffer == null) { return null; }/*from w w w . j a v a 2s. c o m*/ byte[] content = new byte[buffer.position()]; buffer.flip(); buffer.get(content); ByteBuffer newBuffer = ByteBuffer.allocate(buffer.capacity() * 2); newBuffer.put(content); return newBuffer; }
From source file:net.geertvos.theater.core.util.UUIDGen.java
/** creates a type 1 uuid from raw bytes. */ public static UUID getUUID(ByteBuffer raw) { return new UUID(raw.getLong(raw.position()), raw.getLong(raw.position() + 8)); }