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


Scala Arrays类代码示例

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


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

示例1: encrypt

//设置package包名称以及导入依赖的类
package models.user

import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec
import org.apache.commons.codec.binary.Base64
import java.security.MessageDigest
import java.util.Arrays
import controllers.HasConfig

trait HasEncryption { self: HasConfig =>
  
  private val CIPHER = "AES/ECB/PKCS5Padding"
  
  private lazy val keySpec = self.config.getString("recogito.email.key").flatMap { key =>
    if (key.isEmpty) {
      None
    } else {
      val md = MessageDigest.getInstance("SHA-1")
      val keyDigest = md.digest(key.getBytes)
      Some(new SecretKeySpec(Arrays.copyOf(keyDigest, 16), "AES"))
    }
  }
  
  def encrypt(plaintext: String) = keySpec match {
    case Some(spec) => {
      val cipher = Cipher.getInstance(CIPHER)
      cipher.init(Cipher.ENCRYPT_MODE, spec)
      Base64.encodeBase64String(cipher.doFinal(plaintext.getBytes("UTF-8")))
    }
    
    case None => plaintext
  }
  
  def decrypt(encrypted: String) = keySpec match {
    case Some(spec) => {
      val cipher = Cipher.getInstance(CIPHER)
      cipher.init(Cipher.DECRYPT_MODE, spec)
      new String(cipher.doFinal(Base64.decodeBase64(encrypted)))      
    }
    
    case None => encrypted
  }
  
} 
开发者ID:pelagios,项目名称:recogito2,代码行数:45,代码来源:HasEncryption.scala

示例2: ByteString

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

import java.nio.ByteBuffer
import java.nio.charset.Charset
import java.nio.Buffer
import java.util.Arrays

object ByteString {
  private val UTF8 = Charset.forName("UTF8")
  def apply(str: String): ByteString = {
    val result = str.getBytes(UTF8)
    ByteString(result, result.length)
  }
  def apply(arr: Array[Byte]): ByteString = ByteString(arr, arr.length, 0)
  def apply(bb: ByteBuffer): ByteString = {
    val result = bb.array()
    ByteString(result, result.length)
  }
  def copy(bb: Buffer): ByteString = copy(bb.asInstanceOf[ByteBuffer])
  def copy(bb: ByteBuffer): ByteString = {
    val result = Array.ofDim[Byte](bb.remaining)
    bb.get(result)
    ByteString(result, result.length)
  }
}
case class ByteString(arr: Array[Byte], roof: Int, index: Int = 0) {
  def apply(index: Int): Byte = arr(this.index + index)
  def length: Int = roof - index
  def toArray: Array[Byte] = {
    val result = Array.ofDim[Byte](roof - index)
    System.arraycopy(arr, index, result, 0, result.length)
    result
  }
  def toByteBuffer: ByteBuffer = ByteBuffer.wrap(toArray)
  def take(n: Int): ByteString = {
    ByteString(arr, Math.min(arr.length, index + n))
  }
  def isEmpty: Boolean = roof == index
  def head: Byte = arr(index)

  override def toString:String = {
    s"index: $index roof: $roof | ${Arrays.toString(arr)}"
  }
} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:45,代码来源:ByteString.scala

示例3: Checksum

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

import scala.annotation.tailrec
import java.security.MessageDigest
import java.util.Arrays
import org.apache.commons.codec.binary.Hex
import java.nio.ByteBuffer

sealed case class Checksum(sum: Array[Byte], algorithm: Algorithm) {
  def check(other: Array[Byte]): Boolean = {
    check(other.length, other)
  }
  def check(length: Int, other: Array[Byte]*): Boolean = {
      @tailrec
      def rec(length: Int, other: Seq[Array[Byte]], index: Int, digest: MessageDigest): Array[Byte] = {
        if (other.length - 1 == index) {
          digest.update(other(index), 0, length)
          digest.digest
        } else {
          digest.update(other(index))
          rec(length, other, index + 1, digest)
        }
      }
    val digester = MessageDigest.getInstance(algorithm.toString)
    MessageDigest.isEqual(sum, rec(length, other, 0, digester))
  }
  def compare(other: Array[Byte]): Boolean = MessageDigest.isEqual(sum, other)
  override def toString: String = Hex.encodeHexString(sum)
  override def hashCode: Int = Arrays.hashCode(sum)
  override def equals(o: Any): Boolean = o match {
    case Checksum(otherHash, Sha1) => MessageDigest.isEqual(otherHash, sum)
    case _                         => false
  }
}
object Checksum {
  def parse(raw: ByteBuffer, algorithm: Algorithm): Checksum = {
    val checksum = Array.ofDim[Byte](algorithm.bytes)
    for (n <- 0 until algorithm.bytes) {
      checksum(n) = raw.get
    }
    Checksum(checksum, algorithm)
  }
} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:44,代码来源:Checksum.scala

示例4: InfoHash

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

import org.apache.commons.codec.binary.Hex
import java.util.Arrays
import java.security.MessageDigest
import java.nio.ByteBuffer

sealed case class InfoHash(raw: Array[Byte]) {
  override def toString: String = Hex.encodeHexString(raw)
  override def hashCode: Int = Arrays.hashCode(raw)
  override def equals(o: Any): Boolean = o match {
    case InfoHash(otherHash) => MessageDigest.isEqual(otherHash, raw)
    case _                   => false
  }
}
object InfoHash {
  def apply(sha1: Sha1): InfoHash = InfoHash(sha1.raw)
  def hex(hex: String): InfoHash = InfoHash(Hex.decodeHex(hex.toCharArray()))
  def parse(arr: Array[Byte]): InfoHash = {
    println(arr.length)
    assert(arr.length >= 20)
    InfoHash(arr.take(20))
  }
  def parse(buffer: ByteBuffer): InfoHash = {
    assert(buffer.remaining >= 20)
    val result = new Array[Byte](20)
    buffer.get(result)
    InfoHash(result)
  }
} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:31,代码来源:InfoHash.scala

示例5: computeSymmetricCyclicZOrderKey

//设置package包名称以及导入依赖的类
package core.scala

import java.util.Arrays


  def computeSymmetricCyclicZOrderKey(point: Array[Int]): Long = {
    val bitPerDim : Int = LongZKeyBits / point.length
    var sfcKey: Long = 0L
    var mask : Long = 1L
    val dimension : Int = point.length
    val dimMasks : Array[Int] = new Array[Int](point.length)
    Arrays.fill(dimMasks, 1 << (bitPerDim -1 ))
    var k = dimension * bitPerDim
    for ( i <- 0 until (dimension * bitPerDim) ){
      var pointI = point(i % dimension) // cyclic symmetric
      pointI = pointI & dimMasks(i % dimension)
      dimMasks(i % dimension) = dimMasks(i % dimension) >> 1
      if(pointI != 0){
        mask = 1 << (k-1)
        sfcKey |=  mask
      }
      k -= 1
    }
    sfcKey
  }
} 
开发者ID:daniarleagk,项目名称:rbulkloading,代码行数:27,代码来源:SfcFunction.scala

示例6: RelationFace

//设置package包名称以及导入依赖的类
package pl.writeonly.babel.swt.faces

import org.eclipse.jface.viewers.TableViewer
import org.eclipse.swt.widgets.Display
import org.eclipse.swt.widgets.Table
import com.coconut_palm_software.xscalawt.viewers.TableViewerBuilder
import com.weiglewilczek.slf4s.Logging
import javax.annotation.Resource
import pl.writeonly.babel.beans.RecordBean
import pl.writeonly.babel.beans.RelationBean
import pl.writeonly.babel.beans.WordBean
import pl.writeonly.babel.entities.Relation
import pl.writeonly.babel.swt.Face
import pl.writeonly.babel.swt.FaceBuilder
import pl.writeonly.babel.swt.cards.RelationCard
import pl.writeonly.babel.swt.providers.RelationTableProvider
import pl.writeonly.scala.util.SingleAbstractMethod._
import com.google.gson.Gson
import java.util.Arrays
import pl.writeonly.babel.swt.Facade

@org.springframework.stereotype.Controller
class RelationFace extends FaceBuilder[Relation] {
  @Resource var relationService: RelationBean = _
  @Resource var tableProvider: RelationTableProvider = _
  @Resource var recordService: RecordBean = _
  @Resource var parseService: ParseBean = _
  @Resource var facade: Facade = _

  def apply() = RelationCard(this)

  def insert = relationService.persistAll (check())
  //  def find = try { addAll(relationService.find) } catch { case e: RuntimeException => runtime(e)}
  def recordAll = recordService.toRecordAll(check())
  def find = clear.addAll(relationService.find)
  def toJson = logger debug new Gson().toJson(Arrays.asList(tableProvider.array))
  def deen = parseService.deen (facade.open.getFileName())

  protected def clear() = { builder.table.clearAll(); this }
  def addAll(list: List[Relation]) {
    logger debug "addAll list => " + list
    tableProvider.add(list.toArray)
    Display.getDefault.syncExec { list.foreach(builder.viewer.add(_)) }
  }
} 
开发者ID:writeonly,项目名称:babel,代码行数:46,代码来源:RelationFace.scala

示例7: start

//设置package包名称以及导入依赖的类
package org.allenai.pnp.semparse

import java.util.Arrays

import com.google.common.base.Preconditions
import com.jayantkrish.jklol.ccg.lambda.Type
import com.jayantkrish.jklol.ccg.lambda2.Expression2
import edu.cmu.dynet.Expression


  def start(): SemanticParserState = {
    SemanticParserState(Map.empty, List(), 1, 0, null, List(), List())
  }
}

case class ExpressionPart(val expr: Expression2,
    val holes: Array[Int], val holeIds: Array[Int]) {
  Preconditions.checkArgument(holes.length == holeIds.length)
  
  override def toString: String = {
    "ExpressionPart(" + expr + ", " + Arrays.toString(holes) + ", " + Arrays.toString(holeIds) 
  }
}

case class Hole(id: Int, t: Type, scope: Scope, repeated: Boolean) 
开发者ID:allenai,项目名称:pnp,代码行数:26,代码来源:SemanticParserState.scala

示例8: TFieldBlob

//设置package包名称以及导入依赖的类
package de.envisia.play.thrift

import java.util.Arrays

import org.apache.thrift.protocol._
import org.apache.thrift.transport.{ TMemoryBuffer, TMemoryInputTransport }

object TFieldBlob {
  def read(field: TField, iprot: TProtocol): TFieldBlob = {
    capture(field) { ThriftUtil.transfer(_, iprot, field.`type`) }
  }

  def capture(field: TField)(f: TProtocol => Unit): TFieldBlob = {
    val buff = new TMemoryBuffer(32)
    val bprot = new TCompactProtocol(buff)
    f(bprot)
    val data = Arrays.copyOfRange(buff.getArray, 0, buff.length)
    TFieldBlob(field, data)
  }
}


  override def equals(other: Any): Boolean =
    other match {
      // TField does not override the correct equals method, but instead implements
      // an equals method with a different signature, so we need to call .equals
      // instead of using ==
      case TFieldBlob(field2, data2) => field.equals(field2) && Arrays.equals(data, data2)
      case _ => false
    }
} 
开发者ID:envisia,项目名称:play-thrift,代码行数:32,代码来源:TFieldBlob.scala

示例9: Rscript

//设置package包名称以及导入依赖的类
package SparkWorker

import java.io.{File, FileWriter}
import java.util.Arrays

import org.apache.spark._
import org.apache.spark.rdd.RDD
import org.apache.spark.sql._

import ClassUtils._
import FileUtils._

import sparklyr.Logger

class Rscript(logger: Logger) {
  def workerSourceFile(): String = {
    val source = Embedded.sources

    val tempFile: File = new File(createTempDir + File.separator + "sparkworker.R")
    val outStream: FileWriter = new FileWriter(tempFile)
    outStream.write(source)
    outStream.flush()

    tempFile.getAbsolutePath()
  }

  def init(sessionId: Int) = {
    val sparkConf = SparkEnv.get.conf
    val command: String = sparkConf.get("spark.r.command", "Rscript")

    val sourceFilePath: String = workerSourceFile()
    logger.log("Path to source file " + sourceFilePath)

    val processBuilder: ProcessBuilder = new ProcessBuilder(Arrays.asList(
      command,
      "--vanilla",
      sourceFilePath,
      sessionId.toString
    ))

    processBuilder.redirectErrorStream(true);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);

    logger.log("R process starting")
    val process: Process = processBuilder.start()
    val status: Int = process.waitFor()

    if (status == 0) {
      logger.log("R process completed")
    } else {
      logger.logError("R process failed")

      throw new Exception(s"sparklyr worker rscript failure, check worker logs for details.")
    }
  }
} 
开发者ID:javierluraschi,项目名称:sparkworker,代码行数:57,代码来源:rscript.scala

示例10: TempFileTest

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

import java.io.{ByteArrayInputStream, DataInputStream}
import java.util.Arrays

import org.junit.runner.RunWith
import org.scalatest.WordSpec
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class TempFileTest extends WordSpec {

  "TempFile" should {

    "load resources" in {
      val f1 = TempFile.fromResourcePath("/java/lang/String.class")
      val f2 = TempFile.fromResourcePath(getClass, "/java/lang/String.class")
      val f3 = TempFile.fromSystemResourcePath("java/lang/String.class")

      val c1 = Files.readBytes(f1)
      val c2 = Files.readBytes(f2)
      val c3 = Files.readBytes(f3)

      assert(Arrays.equals(c1, c2))
      assert(Arrays.equals(c2, c3))
      assert(new DataInputStream(new ByteArrayInputStream(c1)).readInt == 0xcafebabe)
    }

  }

} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:32,代码来源:TempFileTest.scala

示例11: Pinger

//设置package包名称以及导入依赖的类
package tas.service

import java.util.Arrays
import tas.types.Interval
import tas.concurrency.RunLoop

private object Pinger {
  val PingPacket = Array[Byte]()
}

private abstract class Pinger(runLoop:RunLoop,
                              interval:Interval,
                              timeout:Interval) {

  private var _pingTimeout:RunLoop.DelayedTask = null
  private var _pingRequest:RunLoop.DelayedTask = null

  repostTimeout()

  sendPing()
  postSendPing()
  


  def consumePing(buffer:Array[Byte]) = {
    if (Arrays.equals(buffer, Pinger.PingPacket)) {
      // it is ping
      repostTimeout()
      true
    } else false
  }

  private def repostTimeout() = {
    if (_pingTimeout != null) {
      _pingTimeout.cancel()
    }

    
    _pingTimeout = runLoop.postDelayed(timeout,
                                       onPingTimedOut _)
  }

  private def postSendPing():Unit = {
    _pingRequest = runLoop.postDelayed(interval,
                                       () => {
                                         sendPing()
                                         postSendPing()
                                       })
  }

  protected def sendPing()
  protected def onPingTimedOut()

  def stop() = {
    _pingTimeout.cancel()
    _pingRequest.cancel()
  }
} 
开发者ID:7ocb,项目名称:forex-trade-and-analysis-framework,代码行数:59,代码来源:Pinger.scala

示例12: Public

//设置package包名称以及导入依赖的类
package de.dangoe.freda.jooq.generated.public


import de.dangoe.freda.jooq.generated.DefaultCatalog
import de.dangoe.freda.jooq.generated.public.tables.Accounts
import de.dangoe.freda.jooq.generated.public.tables.Users

import java.util.ArrayList
import java.util.Arrays
import java.util.List

import javax.annotation.Generated

import org.jooq.Catalog
import org.jooq.Table
import org.jooq.impl.SchemaImpl

import scala.Array


object Public {

  
@Generated(
  value = Array(
    "http://www.jooq.org",
    "jOOQ version:3.9.4"
  ),
  comments = "This class is generated by jOOQ"
)
class Public extends SchemaImpl("PUBLIC", DefaultCatalog.DEFAULT_CATALOG) {

  override def getCatalog : Catalog = DefaultCatalog.DEFAULT_CATALOG

  override def getTables : List[Table[_]] = {
    val result = new ArrayList[Table[_]]
    result.addAll(getTables0)
    result
  }

  private def getTables0(): List[Table[_]] = {
    return Arrays.asList[Table[_]](
      Accounts.ACCOUNTS,
      Users.USERS)
  }
} 
开发者ID:dangoe,项目名称:freda,代码行数:47,代码来源:Public.scala


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