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


Scala RandomStringUtils类代码示例

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


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

示例1: Util

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

import java.util.Random

import org.apache.commons.lang3.RandomStringUtils


object Util {

  import java.net._

  def md5Hash(text: String): String = {
    val hash = text + InetAddress.getLocalHost.getHostName
    java.security.MessageDigest.getInstance("MD5").digest(hash.getBytes()).map(0xFF & _).map {
      "%02x".format(_)
    }.foldLeft("") {
      _ + _
    }
  }


  private def generateOrganisationCode(name: String): String = {
    val count: Int = 4
    val useLetters: Boolean = true
    val useNumbers: Boolean = false
    val choseFrom = name.toCharArray
    RandomStringUtils.random(count, 0, 0, useLetters, useNumbers, choseFrom, new Random())
  }

  private def getSalt(): String = {
    val length: Int = 5
    val useLetters: Boolean = true
    val useNumbers: Boolean = true
    RandomStringUtils.random(length, useLetters, useNumbers)
  }

  def codeGen(name: String): String = {
    val code = generateOrganisationCode(name)
      .toCharArray
      .sortWith(_ < _)
      .mkString("").toUpperCase

    val salt = getSalt()
      .toCharArray
      .sortWith(_ < _)
      .mkString("").toUpperCase
    (code + "-" + salt)
  }
} 
开发者ID:Masebeni,项目名称:hwork,代码行数:50,代码来源:Util.scala

示例2: MetaTagReaderSpec

//设置package包名称以及导入依赖的类
package com.clemble.loveit.thank.service

import com.clemble.loveit.common.ServiceSpec
import com.clemble.loveit.common.model.HttpResource
import org.apache.commons.lang3.RandomStringUtils
import org.junit.runner.RunWith
import org.specs2.concurrent.ExecutionEnv
import org.specs2.runner.JUnitRunner

class MetaTagReaderSpec(implicit val ee: ExecutionEnv) extends ServiceSpec {

  lazy val tagReader = dependency[MetaTagReader]

  "READ meta with different number of spaces" in {
    MetaTagReader.findInHtml("<meta name=\"loveit-site-verification\" content=\"1\"") shouldEqual Some("1")
    MetaTagReader.findInHtml("<meta    name=\"loveit-site-verification\"  content=\"1\"") shouldEqual Some("1")
    MetaTagReader.findInHtml("<meta    name=\"loveit-site-verification\"content=\"1\"") shouldEqual Some("1")
    MetaTagReader.findInHtml("<metaname=\"loveit-site-verification\" content=\"1\"") shouldEqual None
  }

  "IGNORE broken url" in {
    val brokenRes = HttpResource(s"http://${RandomStringUtils.randomAlphabetic(10)}.com/")
    await(tagReader.read(brokenRes)) shouldEqual None
  }

} 
开发者ID:thankyo,项目名称:thank,代码行数:27,代码来源:MetaTagReaderSpec.scala

示例3: SendKafka

//设置package包名称以及导入依赖的类
//package teleporter.stream.integration.transaction

import akka.Done
import akka.stream.scaladsl.{Keep, Sink, Source}
import akka.stream.{KillSwitch, KillSwitches}
import org.apache.commons.lang3.RandomStringUtils
import org.apache.kafka.clients.producer.ProducerRecord
import teleporter.integration.component.Kafka
import teleporter.integration.core.Streams.StreamLogic
import teleporter.integration.core.{Message, TeleporterCenter}
import teleporter.integration.utils.Bytes._

import scala.concurrent.Future
import scala.concurrent.duration._


object SendKafka extends StreamLogic {
  override def apply(key: String, center: TeleporterCenter): (KillSwitch, Future[Done]) = {
    println("--------------SendKafka---------------------")
    import center.{materializer, self}
    Source.tick(1.second, 1.second, "test")
      .map { _ ?
        val s = RandomStringUtils.randomAlphabetic(10)
        println(s)
        Message(data = new ProducerRecord[Array[Byte], Array[Byte]]("ppp", "1", s))
      }
      .via(Kafka.flow("/sink/test/test_task/kafka_send/send_sink"))
      .viaMat(KillSwitches.single)(Keep.right).watchTermination()(Keep.both)
      .to(Sink.ignore).run()
  }
} 
开发者ID:huanwuji,项目名称:teleporter,代码行数:32,代码来源:SendKafka.scala

示例4: AuthenticationServiceImpl

//设置package包名称以及导入依赖的类
package services.security.Impl

import org.apache.commons.lang3.RandomStringUtils
import org.mindrot.jbcrypt.BCrypt
import services.security.AuthenticationService


class AuthenticationServiceImpl extends AuthenticationService{
  override def getHashedPassword(password: String): String = {
    BCrypt.hashpw(password, BCrypt.gensalt(12))
  }

  override def generateRandomPassword(): String = {
    val length: Int = 8
    val useLetters: Boolean = true
    val useNumbers: Boolean = true
    RandomStringUtils.random(length, useLetters, useNumbers)
  }

  override def checkPassword(candidate: String, hashed: String): Boolean = {
    BCrypt.checkpw(candidate, hashed)
  }
} 
开发者ID:boniface,项目名称:infoshareapi,代码行数:24,代码来源:AuthenticationServiceImpl.scala


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