private void getBytes(int index, byte[] dst, int dstIndex, int length, boolean internal) { checkDstIndex(index, length, dstIndex, dst.length); ByteBuffer tmpBuf; if (internal) { tmpBuf = internalNioBuffer(); } else { tmpBuf = buffer.duplicate(); } tmpBuf.clear().position(index).limit(index + length); tmpBuf.get(dst, dstIndex, length); }
if (in.remaining() < 6) { throw new IOException(PREMATURE_EOS); flg = FLG.fromByte(in.get()); maxBlockSize = BD.fromByte(in.get()).getBlockMaximumSize(); if (in.remaining() < 8) { throw new IOException(PREMATURE_EOS); int len = in.position() - in.reset().position(); CHECKSUM.hash(in, in.position(), len, 0); in.position(in.position() + len); if (in.get() != (byte) ((hash >> 8) & 0xFF)) { throw new IOException(DESCRIPTOR_HASH_MISMATCH);
@Override public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { ensureAccessible(); if (length == 0) { return this; } if (buffer.hasArray()) { out.write(buffer.array(), index + buffer.arrayOffset(), length); } else { byte[] tmp = ByteBufUtil.threadLocalTempArray(length); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index); tmpBuf.get(tmp, 0, length); out.write(tmp, 0, length); } return this; }
@Override public int setBytes(int index, InputStream in, int length) throws IOException { ensureAccessible(); if (buffer.hasArray()) { return in.read(buffer.array(), buffer.arrayOffset() + index, length); } else { byte[] tmp = ByteBufUtil.threadLocalTempArray(length); int readBytes = in.read(tmp, 0, length); if (readBytes <= 0) { return readBytes; } ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index); tmpBuf.put(tmp, 0, readBytes); return readBytes; } }
/** * Try to read an EOL incrementing the buffer position if successful. * @return whether an EOL was consumed */ private boolean tryConsumeEndOfLine(ByteBuffer byteBuffer) { if (byteBuffer.remaining() > 0) { byte b = byteBuffer.get(); if (b == '\n') { return true; } else if (b == '\r') { if (byteBuffer.remaining() > 0 && byteBuffer.get() == '\n') { return true; } else { throw new StompConversionException("'\\r' must be followed by '\\n'"); } } // Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer ((Buffer) byteBuffer).position(byteBuffer.position() - 1); } return false; }
ByteBuffer outBuf = codecOutputBuffers[index]; outBuf.position(info.offset); outBuf.limit(info.offset + outBitsSize); try { byte[] data = new byte[outPacketSize]; //space for ADTS header included addADTStoPacket(data, outPacketSize); outBuf.get(data, 7, outBitsSize); outBuf.position(info.offset); mFileStream.write(data, 0, outPacketSize); //open FileOutputStream beforehand } catch (IOException e) {
@Override public int setBytes(int index, FileChannel in, long position, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf, position); } catch (ClosedChannelException ignored) { return -1; } }
@Override public ByteBuffer asByteBuffer(int index, int length) { checkIndex(index, length); ByteBuffer duplicate = this.byteBuffer.duplicate(); // Explicit access via Buffer base type for compatibility // with covariant return type on JDK 9's ByteBuffer... Buffer buffer = duplicate; buffer.position(index); buffer.limit(index + length); return duplicate.slice(); }
private int getBytes(int index, FileChannel out, long position, int length, boolean internal) throws IOException { ensureAccessible(); if (length == 0) { return 0; } ByteBuffer tmpBuf = internal ? internalNioBuffer() : buffer.duplicate(); tmpBuf.clear().position(index).limit(index + length); return out.write(tmpBuf, position); }
@Override public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { ensureAccessible(); if (length == 0) { return this; } if (buffer.hasArray()) { out.write(buffer.array(), index + buffer.arrayOffset(), length); } else { byte[] tmp = ByteBufUtil.threadLocalTempArray(length); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index); tmpBuf.get(tmp, 0, length); out.write(tmp, 0, length); } return this; }
@Override public int setBytes(int index, InputStream in, int length) throws IOException { checkIndex(index, length); byte[] tmp = ByteBufUtil.threadLocalTempArray(length); int readBytes = in.read(tmp, 0, length); if (readBytes <= 0) { return readBytes; } ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(idx(index)); tmpBuf.put(tmp, 0, readBytes); return readBytes; }
if (n > 0) { n = Math.min(n, len); ((ByteBuffer) compressedDirectBuf).get(b, off, n); bytesWritten += n; return n; compressedDirectBuf.limit(0); if (0 == uncompressedDirectBuf.position()) { if (0 == uncompressedDirectBuf.position()) { compressedDirectBuf.limit(n); ((ByteBuffer) compressedDirectBuf).get(b, off, n);