當前位置: 首頁>>代碼示例>>Java>>正文


Java SeekableByteChannel.size方法代碼示例

本文整理匯總了Java中java.nio.channels.SeekableByteChannel.size方法的典型用法代碼示例。如果您正苦於以下問題:Java SeekableByteChannel.size方法的具體用法?Java SeekableByteChannel.size怎麽用?Java SeekableByteChannel.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.channels.SeekableByteChannel的用法示例。


在下文中一共展示了SeekableByteChannel.size方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: xorFiles

import java.nio.channels.SeekableByteChannel; //導入方法依賴的package包/類
public static void xorFiles(SeekableByteChannel inputA, SeekableByteChannel inputB,
                            SeekableByteChannel outputChannel, long limit) throws IOException {
	ByteBuffer aBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
	ByteBuffer bBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
	ByteBuffer outBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);

	do {
		if (inputA.position() == inputA.size()) inputA.position(0);
		if (inputB.position() == inputB.size()) inputB.position(0);

		inputA.read(aBuffer);
		inputB.read(bBuffer);
		aBuffer.flip();
		bBuffer.flip();
		int cap = min(aBuffer.remaining(), bBuffer.remaining(), outBuffer.remaining());
		for (int i = 0; i < cap; i += 8) {
			long a = aBuffer.getLong();
			long b = bBuffer.getLong();
			outBuffer.putLong(a ^ b);
		}
		aBuffer.compact();
		bBuffer.compact();

		outBuffer.flip();
		long bytesRequired = limit - outputChannel.size();
		if (outBuffer.limit() > bytesRequired) outBuffer.limit((int) bytesRequired);
		outputChannel.write(outBuffer);
		outBuffer.compact();
	} while (outputChannel.size() < limit);
}
 
開發者ID:zeobviouslyfakeacc,項目名稱:ModLoaderInstaller,代碼行數:31,代碼來源:FileUtils.java


注:本文中的java.nio.channels.SeekableByteChannel.size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。