List of usage examples for java.nio ByteBuffer position
public final int position()
From source file:Main.java
public static boolean isPredessorEqualsP(ByteBuffer bb1, ByteBuffer bb2) { return isPredessorEquals(bb1, bb1.position(), bb1.remaining(), bb2, bb2.position(), bb2.remaining()); }
From source file:Main.java
public final static boolean equalsP(final ByteBuffer bb, final byte[] bytes) { return equals(bb.array(), bb.position(), bytes); }
From source file:Main.java
public final static boolean containsP(final ByteBuffer bb1, final ByteBuffer bb2) { return contains(bb1.array(), bb1.position(), bb1.limit(), bb2.array(), bb2.position(), bb2.limit()); }
From source file:Main.java
public static final int stripP(ByteBuffer bb, final byte crimpChar) { final byte[] array = bb.array(); final int position = bb.position(); final int limit = bb.limit(); return bb.limit(strip(array, position, limit, crimpChar)).limit(); }
From source file:Main.java
/** * Like {@link #parseEAc3SyncframeAudioSampleCount(byte[])} but reads from a byte buffer. The * buffer position is not modified./*from w ww. j a v a 2s . c o m*/ * * @see #parseEAc3SyncframeAudioSampleCount(byte[]) */ public static int parseEAc3SyncframeAudioSampleCount(ByteBuffer buffer) { // See ETSI TS 102 366 subsection E.1.2.2. int fscod = (buffer.get(buffer.position() + 4) & 0xC0) >> 6; return AUDIO_SAMPLES_PER_AUDIO_BLOCK * (fscod == 0x03 ? 6 : BLOCKS_PER_SYNCFRAME_BY_NUMBLKSCOD[(buffer.get(buffer.position() + 4) & 0x30) >> 4]); }
From source file:Main.java
public static final boolean isSuccessorP(final ByteBuffer bb1, final ByteBuffer bb2) { return isSuccessor(bb1, bb1.position(), bb1.remaining(), bb2, bb2.position(), bb2.remaining()); }
From source file:Main.java
/** * Reads the number of audio samples represented by a TrueHD syncframe. The buffer's position is * not modified.//from w ww. ja v a 2s .c om * * @param buffer The {@link ByteBuffer} from which to read the syncframe. * @param offset The offset of the start of the syncframe relative to the buffer's position. * @return The number of audio samples represented by the syncframe. */ public static int parseTrueHdSyncframeAudioSampleCount(ByteBuffer buffer, int offset) { // TODO: Link to specification if available. boolean isMlp = (buffer.get(buffer.position() + offset + 7) & 0xFF) == 0xBB; return 40 << ((buffer.get(buffer.position() + offset + (isMlp ? 9 : 8)) >> 4) & 0x07); }
From source file:Main.java
public final static void replaceP(final ByteBuffer lineBB, final byte from, final byte to) { final byte[] array = lineBB.array(); final int offset = lineBB.position(); final int limit = lineBB.limit(); replace(array, offset, limit, from, to); }
From source file:Main.java
public static void copy(ReadableByteChannel in, WritableByteChannel out) throws IOException { // First, we need a buffer to hold blocks of copied bytes. ByteBuffer buffer = ByteBuffer.allocateDirect(32 * 1024); // Now loop until no more bytes to read and the buffer is empty while (in.read(buffer) != -1 || buffer.position() > 0) { // The read() call leaves the buffer in "fill mode". To prepare // to write bytes from the bufferwe have to put it in "drain mode" // by flipping it: setting limit to position and position to zero buffer.flip();/*ww w . ja v a 2s. c om*/ // Now write some or all of the bytes out to the output channel out.write(buffer); // Compact the buffer by discarding bytes that were written, // and shifting any remaining bytes. This method also // prepares the buffer for the next call to read() by setting the // position to the limit and the limit to the buffer capacity. buffer.compact(); } }
From source file:Main.java
/** * Finds next Nth MPEG bitstream marker 0x000001xx and returns the data that * preceeds it as a ByteBuffer slice// w w w .ja va 2 s . co m * * Segment byte order is always little endian * * @param buf * @return */ public static final ByteBuffer gotoMarker(ByteBuffer buf, int n, int mmin, int mmax) { if (!buf.hasRemaining()) return null; int from = buf.position(); ByteBuffer result = buf.slice(); result.order(ByteOrder.BIG_ENDIAN); int val = 0xffffffff; while (buf.hasRemaining()) { val = (val << 8) | (buf.get() & 0xff); if (val >= mmin && val <= mmax) { if (n == 0) { buf.position(buf.position() - 4); result.limit(buf.position() - from); break; } --n; } } return result; }