Java Code Examples for java.nio.channels.ScatteringByteChannel#read()
The following examples show how to use
java.nio.channels.ScatteringByteChannel#read() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeapChannelBuffer.java From dubbox with Apache License 2.0 | 6 votes |
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
Example 2
Source File: HeapChannelBuffer.java From dubbo3 with Apache License 2.0 | 6 votes |
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
Example 3
Source File: HeapChannelBuffer.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
Example 4
Source File: HeapChannelBuffer.java From dubbox with Apache License 2.0 | 6 votes |
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
Example 5
Source File: HeapChannelBuffer.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
Example 6
Source File: UnpooledUnsafeDirectByteBuf.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
Example 7
Source File: UnpooledDirectByteBuf.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpNioBuf); } catch (ClosedChannelException ignored) { return -1; } }
Example 8
Source File: MultiQpidByteBuffer.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Override public final long read(ScatteringByteChannel channel) throws IOException { ByteBuffer[] byteBuffers = new ByteBuffer[_fragments.length]; for (int i = 0; i < byteBuffers.length; i++) { final SingleQpidByteBuffer fragment = _fragments[i]; byteBuffers[i] = fragment.getUnderlyingBuffer(); } return channel.read(byteBuffers); }
Example 9
Source File: PooledHeapByteBuf.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); index = idx(index); try { return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)); } catch (ClosedChannelException ignored) { return -1; } }
Example 10
Source File: PacketTracer.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public int writeBytes(ScatteringByteChannel ch, int max) throws IOException { ByteBuffer tmp = ByteBuffer.allocateDirect(max); int length = ch.read(tmp); writeBytes(tmp); return length; }
Example 11
Source File: PooledDirectByteBuf.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, 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); } catch (ClosedChannelException ignored) { return -1; } }
Example 12
Source File: UnpooledUnsafeDirectByteBuf.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
Example 13
Source File: PooledUnsafeDirectByteBuf.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, 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); } catch (ClosedChannelException ignored) { return -1; } }
Example 14
Source File: UnpooledHeapByteBuf.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); try { return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)); } catch (ClosedChannelException ignored) { return -1; } }
Example 15
Source File: UnpooledDirectByteBuf.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpNioBuf); } catch (ClosedChannelException ignored) { return -1; } }
Example 16
Source File: NetworkBuffer.java From flink with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { // adapted from UnpooledDirectByteBuf: checkIndex(index, length); ByteBuffer tmpBuf = memorySegment.wrap(index, length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
Example 17
Source File: NetworkBuffer.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { // adapted from UnpooledDirectByteBuf: checkIndex(index, length); ByteBuffer tmpBuf = memorySegment.wrap(index, length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
Example 18
Source File: CompositeByteBuf.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); if (length == 0) { return in.read(EMPTY_NIO_BUFFER); } int i = toComponentIndex(index); int readBytes = 0; do { Component c = components.get(i); ByteBuf s = c.buf; int adjustment = c.offset; int localLength = Math.min(length, s.capacity() - (index - adjustment)); if (localLength == 0) { // Skip empty buffer i++; continue; } int localReadBytes = s.setBytes(index - adjustment, in, localLength); if (localReadBytes == 0) { break; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } if (localReadBytes == localLength) { index += localLength; length -= localLength; readBytes += localLength; i ++; } else { index += localReadBytes; length -= localReadBytes; readBytes += localReadBytes; } } while (length > 0); return readBytes; }
Example 19
Source File: SingleQpidByteBuffer.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Override public final long read(ScatteringByteChannel channel) throws IOException { return channel.read(getUnderlyingBuffer()); }
Example 20
Source File: CompositeByteBuf.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); if (length == 0) { return in.read(EMPTY_NIO_BUFFER); } int i = toComponentIndex(index); int readBytes = 0; do { Component c = components.get(i); ByteBuf s = c.buf; int adjustment = c.offset; int localLength = Math.min(length, s.capacity() - (index - adjustment)); int localReadBytes = s.setBytes(index - adjustment, in, localLength); if (localReadBytes == 0) { break; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } if (localReadBytes == localLength) { index += localLength; length -= localLength; readBytes += localLength; i ++; } else { index += localReadBytes; length -= localReadBytes; readBytes += localReadBytes; } } while (length > 0); return readBytes; }