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


Scala MapMode类代码示例

本文整理汇总了Scala中java.nio.channels.FileChannel.MapMode的典型用法代码示例。如果您正苦于以下问题:Scala MapMode类的具体用法?Scala MapMode怎么用?Scala MapMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MapMode类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: TorrentFileStream

//设置package包名称以及导入依赖的类
package com.spooky.bencode

import scala.collection.JavaConversions._
import java.io.File
import java.nio.channels.FileChannel
import java.nio.file.StandardOpenOption
import java.nio.channels.FileChannel.MapMode
import java.nio.ByteBuffer
import scala.Range

class TorrentFileStream(channel: FileChannel, buffer: ByteBuffer) extends BStream {
  def headChar: Char = buffer.duplicate.get.asInstanceOf[Char]
  def headByte: Byte = buffer.duplicate.get
  def tail = {
    val tail = buffer.duplicate
    tail.get
    new TorrentFileStream(channel, tail)
  }
  def isEmpty = !buffer.hasRemaining
  def close: Unit = channel.close
  override def toString: String = {
    val buff = buffer.duplicate
    val builder = StringBuilder.newBuilder
    while (buff.hasRemaining) {
      if (builder.endsWith("6:pieces")) {
        val bah = StringBuilder.newBuilder
        var chaaa = buff.get.asInstanceOf[Char]
        while ("0123456789".contains(chaaa)) {
          bah.append(chaaa)
          chaaa = buff.get.asInstanceOf[Char]
        }
        var i = bah.toString.toInt
        while(i >= 0){
          buff.get
          i = i-1
        }
      }
      builder += buff.get.asInstanceOf[Char]
    }
    builder.toString
  }
}
object TorrentFileStream {
  def apply(torrent: File) = {
    val channel = FileChannel.open(torrent.toPath, StandardOpenOption.READ)
    new TorrentFileStream(channel, channel.map(MapMode.READ_ONLY, 0, channel.size).load)
  }
} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:49,代码来源:TorrentFileStream.scala

示例2: ImmutableTest

//设置package包名称以及导入依赖的类
package com.github.sorhus.webalytics.cruft

import java.io.{DataOutputStream, File, FileOutputStream, RandomAccessFile}
import java.nio.channels.FileChannel.MapMode

import org.roaringbitmap.RoaringBitmap
import org.roaringbitmap.buffer.ImmutableRoaringBitmap

object ImmutableTest extends App {

  val outFile = new File(args(0))
  outFile.createNewFile()
  val fos = new FileOutputStream(outFile)
  val dos = new DataOutputStream(fos)
  val x = RoaringBitmap.bitmapOf(1,3,5)
  x.runOptimize()
  x.serialize(dos)
  dos.close()

  val inFile = new RandomAccessFile(args(0), "r")
  val memoryMapped = inFile.getChannel.map(MapMode.READ_ONLY, 0, inFile.length())
  val bb = memoryMapped.slice()
  val bitset = new ImmutableRoaringBitmap(bb)

  println(ImmutableRoaringBitmap.and(bitset,bitset).getCardinality)
  println(ImmutableRoaringBitmap.andCardinality(bitset,bitset))

  inFile.close()
} 
开发者ID:sorhus,项目名称:webalytics,代码行数:30,代码来源:ImmutableTest.scala


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