/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
int init() { int totalRemaining = 0; for (int i = 0; i < bufferCount; ++i) { ByteBuffer b = byteBuffers[i + offset]; if (direction == Direction.READV) { b.checkWritable(); } int remaining = b.remaining(); if (b.isDirect()) { ioBuffers[i] = b; offsets[i] = b.position(); } else { ioBuffers[i] = NioUtils.unsafeArray(b); offsets[i] = NioUtils.unsafeArrayOffset(b) + b.position(); } byteCounts[i] = remaining; totalRemaining += remaining; } return totalRemaining; }
@Override public int read(ByteBuffer target) throws IOException { target.checkWritable(); checkOpenConnected(); if (!target.hasRemaining()) { return 0; } int readCount = 0; if (target.isDirect() || target.hasArray()) { readCount = readImpl(target); if (readCount > 0) { target.position(target.position() + readCount); } } else { byte[] readArray = new byte[target.remaining()]; ByteBuffer readBuffer = ByteBuffer.wrap(readArray); readCount = readImpl(readBuffer); if (readCount > 0) { target.put(readArray, 0, readCount); } } return readCount; }
private int readImpl(ByteBuffer buffer, long position) throws IOException { buffer.checkWritable(); checkOpen(); checkReadable();
@Override public SocketAddress receive(ByteBuffer target) throws IOException { target.checkWritable(); checkOpen(); if (!isBound) { return null; } SocketAddress retAddr = null; try { begin(); // receive real data packet, (not peek) synchronized (readLock) { boolean loop = isBlocking(); if (!target.isDirect()) { retAddr = receiveImpl(target, loop); } else { retAddr = receiveDirectImpl(target, loop); } } } catch (InterruptedIOException e) { // this line used in Linux return null; } finally { end(retAddr != null); } return retAddr; }
/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
/** * @param copyingIn true if we're copying data into the buffers (typically * because the caller is a file/network read operation), false if we're * copying data out of the buffers (for a file/network write operation). */ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) { int count = 0; for (int i = offset; i < offset + length; ++i) { count += buffers[i].remaining(); if (copyingIn) { buffers[i].checkWritable(); } } return count; }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
@Override public int read(ByteBuffer dst) throws IOException { dst.checkWritable(); checkOpenConnected(); if (!dst.hasRemaining()) { return 0; } return readImpl(dst); }
int init() { int totalRemaining = 0; for (int i = 0; i < bufferCount; ++i) { ByteBuffer b = byteBuffers[i + offset]; if (direction == Direction.READV) { b.checkWritable(); } int remaining = b.remaining(); if (b.isDirect()) { ioBuffers[i] = b; offsets[i] = b.position(); } else { ioBuffers[i] = NioUtils.unsafeArray(b); offsets[i] = NioUtils.unsafeArrayOffset(b) + b.position(); } byteCounts[i] = remaining; totalRemaining += remaining; } return totalRemaining; }
int init() { int totalRemaining = 0; for (int i = 0; i < bufferCount; ++i) { ByteBuffer b = byteBuffers[i + offset]; if (direction == Direction.READV) { b.checkWritable(); } int remaining = b.remaining(); if (b.isDirect()) { ioBuffers[i] = b; offsets[i] = b.position(); } else { ioBuffers[i] = NioUtils.unsafeArray(b); offsets[i] = NioUtils.unsafeArrayOffset(b) + b.position(); } byteCounts[i] = remaining; totalRemaining += remaining; } return totalRemaining; }