本文整理汇总了Java中java.nio.channels.ScatteringByteChannel类的典型用法代码示例。如果您正苦于以下问题:Java ScatteringByteChannel类的具体用法?Java ScatteringByteChannel怎么用?Java ScatteringByteChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScatteringByteChannel类属于java.nio.channels包,在下文中一共展示了ScatteringByteChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
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: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
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;
}
}
if (localReadBytes == 0) {
break;
}
readBytes += localReadBytes;
} while (readBytes < length);
return readBytes;
}
示例3: scatter
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
public static void scatter() {
ByteBuffer header = ByteBuffer.allocate(13);
ByteBuffer body = ByteBuffer.allocate(100);
ByteBuffer[] bufferArray = { header, body };
ScatteringByteChannel channel = getChannel();
try {
channel.read(bufferArray);
} catch (IOException e) {
e.printStackTrace();
}
header.rewind();
body.rewind();
String headerStr = convertBufferToString(header);
String bodyStr = convertBufferToString(body);
System.out.println(headerStr);
System.out.println(bodyStr);
}
示例4: writeBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@Override
public int writeBytes(ScatteringByteChannel channel) throws IOException {
if (buffer.readableBytes() > 0) {
this.buffer.markReaderIndex();
this.buffer.discardReadBytes(); // compact the buffer
} else {
buffer.clear();
}
int readBytes = 0;
while (buffer.writableBytes() > 0) {
int localReadBytes = buffer.writeBytes(channel, buffer.writableBytes());
if (localReadBytes < 0) {
break;
}
readBytes += localReadBytes;
}
return readBytes;
}
示例5: writeBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@Override
public int writeBytes(ScatteringByteChannel ch, int max) throws IOException {
ByteBuffer tmp = ByteBuffer.allocateDirect(max);
int length = ch.read(tmp);
writeBytes(tmp);
return length;
}
示例6: writeBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@Override
public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
int writtenBytes = setBytes(writerIndex, in, length);
if (writtenBytes > 0) {
writerIndex += writtenBytes;
}
return writtenBytes;
}
示例7: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@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: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@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;
}
}
示例9: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@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;
}
}
示例10: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@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;
}
}
示例11: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@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;
}
}
示例12: writeBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@Override
public int writeBytes(ScatteringByteChannel in, int length) throws IOException {
ensureAccessible();
ensureWritable(length);
int writtenBytes = setBytes(writerIndex, in, length);
if (writtenBytes > 0) {
writerIndex += writtenBytes;
}
return writtenBytes;
}
示例13: setBytes
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@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;
}
}
示例14: copyFromChannel
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
@Override
public boolean copyFromChannel(ScatteringByteChannel channel) throws IOException {
switch (dataFormat) {
case BuiltinStorages.DRAW:
return fillDrawBuffer(channel);
default:
throw new TajoInternalError(new NotImplementedException("Heap memory writer not implemented yet"));
}
}
示例15: fillDrawBuffer
import java.nio.channels.ScatteringByteChannel; //导入依赖的package包/类
protected boolean fillDrawBuffer(ScatteringByteChannel channel) throws IOException {
reset();
int readBytes = memory.writeBytes(channel);
if (readBytes > 0) {
// get row capacity in buffer
while (memory.isReadable()) {
if (memory.readableBytes() < SizeOf.SIZE_OF_INT) {
return true;
}
int recordSize = PlatformDependent.getInt(memory.address() + memory.readerPosition());
assert recordSize > 0;
if (memory.readableBytes() < recordSize) {
return true;
} else {
memory.readerPosition(memory.readerPosition() + recordSize);
}
rowNum++;
}
return true;
} else {
return false;
}
}