类java.nio.channels.ScatteringByteChannel源码实例Demo

下面列出了怎么用java.nio.channels.ScatteringByteChannel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dubbo-2.6.5   文件: HeapChannelBuffer.java
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;
}
 
源代码2 项目: dubbox   文件: HeapChannelBuffer.java
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;
}
 
源代码3 项目: dubbox-hystrix   文件: HeapChannelBuffer.java
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;
}
 
源代码4 项目: dubbo3   文件: HeapChannelBuffer.java
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;
}
 
源代码5 项目: dubbox   文件: HeapChannelBuffer.java
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;
}
 
源代码6 项目: dubbox   文件: HeapChannelBuffer.java
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;
}
 
源代码7 项目: Flink-CEPplus   文件: NetworkBuffer.java
@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;
	}
}
 
源代码8 项目: flink   文件: NetworkBuffer.java
@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;
	}
}
 
源代码9 项目: netty-4.1.22   文件: UnpooledDirectByteBuf.java
@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;
    }
}
 
源代码10 项目: netty-4.1.22   文件: PooledHeapByteBuf.java
@Override
public final 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;
    }
}
 
源代码11 项目: netty-4.1.22   文件: UnpooledHeapByteBuf.java
@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;
    }
}
 
源代码12 项目: netty-4.1.22   文件: PooledUnsafeDirectByteBuf.java
@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;
    }
}
 
源代码13 项目: netty-4.1.22   文件: AbstractByteBuf.java
@Override
public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
    ensureWritable(length);
    int writtenBytes = setBytes(writerIndex, in, length);
    if (writtenBytes > 0) {
        writerIndex += writtenBytes;
    }
    return writtenBytes;
}
 
源代码14 项目: netty-4.1.22   文件: UnpooledUnsafeDirectByteBuf.java
@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;
    }
}
 
源代码15 项目: aion   文件: BasicSliceOutput.java
@Override
public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
    int writtenBytes = slice.setBytes(size, in, length);
    if (writtenBytes > 0) {
        size += writtenBytes;
    }
    return writtenBytes;
}
 
源代码16 项目: aion   文件: Slice.java
/**
 * Transfers the content of the specified source channel to this buffer starting at the
 * specified absolute {@code index}.
 *
 * @param length the maximum number of bytes to transfer
 * @return the actual number of bytes read in from the specified channel. {@code -1} if the
 *     specified channel is closed.
 * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or if
 *     {@code index + length} is greater than {@code this.capacity}
 * @throws java.io.IOException if the specified channel threw an exception during I/O
 */
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
    Preconditions.checkPositionIndexes(index, index + length, this.length);
    index += offset;
    ByteBuffer buf = ByteBuffer.wrap(data, 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;
}
 
源代码17 项目: armeria   文件: WebOperationService.java
private static int read(ReadableByteChannel src, ByteBuf dst) throws IOException {
    if (src instanceof ScatteringByteChannel) {
        return dst.writeBytes((ScatteringByteChannel) src, dst.writableBytes());
    }

    final int readBytes = src.read(dst.nioBuffer(dst.writerIndex(), dst.writableBytes()));
    if (readBytes > 0) {
        dst.writerIndex(dst.writerIndex() + readBytes);
    }
    return readBytes;
}
 
源代码18 项目: PHONK   文件: TransferLearningModel.java
/**
 * Overwrites the current model parameter values with the values read from a channel.
 *
 * The channel should contain values previously written by
 * {@link #saveParameters(GatheringByteChannel)} for the same underlying model.
 *
 * @param inputChannel where to read the parameters from.
 * @throws IOException if an I/O error occurs.
 */
public void loadParameters(ScatteringByteChannel inputChannel) throws IOException {
  parameterLock.writeLock().lock();
  try {
    inputChannel.read(modelParameters);
    for (ByteBuffer buffer : modelParameters) {
      buffer.rewind();
    }
  } finally {
    parameterLock.writeLock().unlock();
  }
}
 
源代码19 项目: qpid-broker-j   文件: MultiQpidByteBuffer.java
@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);
}
 
源代码20 项目: netty4.0.27Learn   文件: UnpooledDirectByteBuf.java
@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;
    }
}
 
源代码21 项目: netty4.0.27Learn   文件: PooledHeapByteBuf.java
@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;
    }
}
 
源代码22 项目: netty4.0.27Learn   文件: UnpooledHeapByteBuf.java
@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;
    }
}
 
@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;
    }
}
 
@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;
    }
}
 
源代码25 项目: armeria   文件: FileSystemHttpFile.java
@Override
protected int read(ByteChannel src, ByteBuf dst) throws IOException {
    if (src instanceof ScatteringByteChannel) {
        return dst.writeBytes((ScatteringByteChannel) src, dst.writableBytes());
    }

    final int readBytes = src.read(dst.nioBuffer(dst.writerIndex(), dst.writableBytes()));
    if (readBytes > 0) {
        dst.writerIndex(dst.writerIndex() + readBytes);
    }
    return readBytes;
}
 
源代码26 项目: netty4.0.27Learn   文件: PooledDirectByteBuf.java
@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;
    }
}
 
源代码27 项目: Bats   文件: DrillBuf.java
@Override
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
  return udle.setBytes(index + offset, in, length);
}
 
源代码28 项目: Bats   文件: MutableWrappedByteBuf.java
@Override
public int setBytes(int index, ScatteringByteChannel in, int length)
    throws IOException {
  return buffer.setBytes(index, in, length);
}
 
源代码29 项目: Bats   文件: DeadBuf.java
@Override
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
  throw new UnsupportedOperationException(ERROR_MESSAGE);
}
 
源代码30 项目: Bats   文件: DeadBuf.java
@Override
public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
  throw new UnsupportedOperationException(ERROR_MESSAGE);

}
 
 类所在包
 类方法
 同包方法