當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。