当前位置: 首页>>代码示例>>Java>>正文


Java ScatteringByteChannel.read方法代码示例

本文整理汇总了Java中java.nio.channels.ScatteringByteChannel.read方法的典型用法代码示例。如果您正苦于以下问题:Java ScatteringByteChannel.read方法的具体用法?Java ScatteringByteChannel.read怎么用?Java ScatteringByteChannel.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.ScatteringByteChannel的用法示例。


在下文中一共展示了ScatteringByteChannel.read方法的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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:26,代码来源:HeapChannelBuffer.java

示例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;
}
 
开发者ID:kennylbj,项目名称:kiwi,代码行数:27,代码来源:HeapBuffer.java

示例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);

	}
 
开发者ID:zoopaper,项目名称:netty-study,代码行数:25,代码来源:ScatterAndGather.java

示例4: 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;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:PacketTracer.java

示例5: 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;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:13,代码来源:NetworkBuffer.java

示例6: 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;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:12,代码来源:UnpooledDirectByteBuf.java

示例7: 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;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:PooledHeapByteBuf.java

示例8: 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;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:10,代码来源:UnpooledHeapByteBuf.java

示例9: 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;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:13,代码来源:PooledUnsafeDirectByteBuf.java

示例10: 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;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:12,代码来源:UnpooledUnsafeDirectByteBuf.java

示例11: 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 e) {
        return -1;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:12,代码来源:UnpooledDirectByteBuf.java

示例12: 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 e) {
        return -1;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:11,代码来源:PooledHeapByteBuf.java

示例13: 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 e) {
        return -1;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:10,代码来源:UnpooledHeapByteBuf.java

示例14: 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 e) {
        return -1;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:13,代码来源:PooledUnsafeDirectByteBuf.java

示例15: 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 e) {
        return -1;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:12,代码来源:UnpooledUnsafeDirectByteBuf.java


注:本文中的java.nio.channels.ScatteringByteChannel.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。