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


Java FileChannel.MapMode方法代碼示例

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


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

示例1: processRegions

import java.nio.channels.FileChannel; //導入方法依賴的package包/類
private void processRegions(File file, RegionProcessor regionProcessor, String randomAccessFileMode, FileChannel.MapMode mapMode) throws IOException {
    try (
            RandomAccessFile randomAccessFile = new RandomAccessFile(file.getAbsolutePath().toFile(), randomAccessFileMode);
            FileChannel channel = randomAccessFile.getChannel()

    ) {
        RegionCalculator.calculateForSize(file, file.getSize());


        for (Region region : file.getRegions().values()) {
            Hasher hasher = Hashing.sha256().newHasher();
            MappedByteBuffer mappedByteBuffer = channel.map(mapMode, region.getOffset(), region.getSize());

            int sum = regionProcessor.processRegion(region, hasher, mappedByteBuffer);

            region.setQuickDigest(sum);

            byte[] slowDigest = hasher.hash().asBytes();
            region.setSlowDigest(slowDigest);

            clientMessageHandler.submitClientRegionMessage(clientId, file, region.getOffset(), region.getSize(), sum, slowDigest);
        }
    }
}
 
開發者ID:gaganis,項目名稱:odoxSync,代碼行數:25,代碼來源:FileOperations.java

示例2: RandomAccessMmapObject

import java.nio.channels.FileChannel; //導入方法依賴的package包/類
public RandomAccessMmapObject(final RandomAccessFile randomAccessFile, String mode)
    throws IOException, IllegalArgumentException {
  if (randomAccessFile.length() > Integer.MAX_VALUE) {
    throw new IllegalArgumentException("Only files up to 2GiB in size are supported.");
  }

  FileChannel.MapMode mapMode;
  if (mode.equals("r")) {
    mapMode = FileChannel.MapMode.READ_ONLY;
  } else {
    mapMode = FileChannel.MapMode.READ_WRITE;
  }

  mFileChannel = randomAccessFile.getChannel();
  mByteBuffer = mFileChannel.map(mapMode, 0, randomAccessFile.length());
  mByteBuffer.position(0);
  mShouldDeleteFileOnRelease = false;
  mFile = null;
}
 
開發者ID:lizhangqu,項目名稱:CorePatch,代碼行數:20,代碼來源:RandomAccessObject.java


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