• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala BaseEncoding类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Files

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

import java.io.FileInputStream
import java.util.UUID

import play.api.Play
import play.api.mvc.{Action, Controller, ResponseHeader, Result}
import com.google.common.io.BaseEncoding
import exceptions.GoogleAuthTokenExpired
import models.File
import play.api.libs.iteratee.Enumerator


object Files extends Controller {

  lazy val oauth2 = new utils.OAuth2(Play.current)

  def fileUpload = Action(parse.multipartFormData) { request =>
    request.body.file("file").map { picture =>
      val fileName = picture.filename
      val contentType = picture.contentType.getOrElse("text/html")
      val fstream = new FileInputStream(picture.ref.file)
      val ftext = BaseEncoding.base64.encode(Stream.continually(fstream.read).takeWhile(_ != -1).map(_.toByte).toArray)
      try {
        val user = oauth2.getUser(request.session)
        // Persist
        File.create(new File(0, user.id, fileName, contentType, ftext))
        // TODO(delyan): this should return file ID perhaps?
        Ok(fileName)
      } catch {
        case expired: GoogleAuthTokenExpired =>
          val state = UUID.randomUUID().toString
          Ok(views.html.index(None, Some(oauth2.getLoginURL(state)), List()))
            .withSession("oauth-state" -> state)
      }
    }.getOrElse {
      Redirect(routes.Users.index)
        .flashing("error" -> "Missing file")
    }
  }

  def file = Action {
    // TODO(delyan): File.get...
    Ok("{}").as("application/json")
  }

  def downloadFile(fileName: String) = Action { request =>
    val user = oauth2.getUser(request.session)
    val file = File.getByName(user.id, fileName)
    // TODO(delyan): File.get...
    val fileContent: Enumerator[Array[Byte]] = Enumerator(BaseEncoding.base64.decode(file.file))
    Result(
      header = ResponseHeader(200),
      body = fileContent
    ).as(file.content_type)
  }

} 
开发者ID:delqn,项目名称:botslandia,代码行数:59,代码来源:Files.scala


示例2: basic644

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.fileupload.support

import com.google.common.base.Charsets
import com.google.common.io.BaseEncoding
import org.scalatest.Suite
import play.api.http.HeaderNames
import play.api.libs.ws.WSResponse
import play.utils.UriEncoding
import uk.gov.hmrc.fileupload.{EnvelopeId, FileId, FileRefId}

trait FileActions extends ActionsSupport {
  this: Suite =>

  def basic644(s:String): String = {
    BaseEncoding.base64().encode(s.getBytes(Charsets.UTF_8))
  }

  def urlEncode(fileId: FileId) = UriEncoding.encodePathSegment(fileId.value, "UTF-8")


  def upload(data: Array[Byte], envelopeId: EnvelopeId, fileId: FileId, fileRefId: FileRefId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/$fileId/$fileRefId")
      .withHeaders("Content-Type" -> "application/octet-stream")
      .put(data)
      .futureValue

  def delete(envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/${urlEncode(fileId)}")
      .delete()
      .futureValue

  def download(envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/${urlEncode(fileId)}/content").withHeaders(HeaderNames.AUTHORIZATION -> ("Basic " + basic644("yuan:yaunspassword")))
      .get()
      .futureValue

  def getFileMetadataFor(envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/${urlEncode(fileId)}/metadata")
      .get()
      .futureValue

  def downloadEnvelope(envelopeId: EnvelopeId): WSResponse =
    client
      .url(s"$fileTransferUrl/envelopes/$envelopeId")
      .get()
      .futureValue
} 
开发者ID:hmrc,项目名称:file-upload,代码行数:52,代码来源:FileActions.scala


示例3: jsonToAny

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

import akka.serialization.Serialization
import com.google.common.io.BaseEncoding
import play.api.libs.json._

package object persistence {

  
  def jsonToAny(v: JsValue)(implicit serialization: Serialization): Any =
    serializedToAny((v \ "vt").as[String], (v \ "v").get)

  protected[persistence] def serializedToAny(typeName: String, json: JsValue)(implicit serialization: Serialization): Any = {
    typeName match {
      case "int" => json.as[Int]
      case "long" => json.as[Long]
      case "float" => json.as[Float]
      case "double" => json.as[Double]
      case "boolean" => json.as[Boolean]
      case "string" => json.as[String]
      case t =>
        val decoded = BaseEncoding.base64().decode(json.as[String])
        serialization.deserialize(decoded, t.toInt, None).get
    }
  }
  
} 
开发者ID:SeanCheatham,项目名称:akka-persistence-firebase,代码行数:28,代码来源:package.scala


示例4: AuthenticatedRequest

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

import com.google.common.io.BaseEncoding

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc._
import play.api.mvc.Results._
import play.api.libs.json._
import models.User
import play.api.Logger
import play.mvc.Http.HeaderNames._
import com.auth0.jwt.JWTVerifier

class AuthenticatedRequest[A](val user: User, val request: Request[A]) extends WrappedRequest[A](request)
class AuthenticatedAsyncRequest[A](user: User, request: Request[A]) extends WrappedRequest[A](request)

trait Secured {
  def SecuredAction = AuthenticatedAction
}

object AuthenticatedAction extends ActionBuilder[AuthenticatedRequest] {

  def invokeBlock[A](request: Request[A], block: AuthenticatedRequest[A] => Future[Result]) ={
    val auth = request.headers.get(AUTHORIZATION)
    if(auth.isDefined) {
      val token = auth.get.substring(6).trim
      val secret = BaseEncoding.base64Url.omitPadding.decode("password")

      val verifier: JWTVerifier = new JWTVerifier(secret, "", "");
      val claims = verifier.verify(token)

      val user = User(claims.get("name").toString,
        claims.get("nickname").toString,
        claims.get("family_name").toString,
        claims.get("user_id").toString,
        claims.get("email").toString,
        claims.get("email_verified").toString,
        claims.get("user_metadata").toString
      )

      Logger.info("user" + user)
      block(new AuthenticatedRequest[A](user, request))
    }
    else{
      block(new AuthenticatedRequest[A](User("Anonymous","", "", "", "", "", ""), request))
    }
  }
} 
开发者ID:adrienpessu,项目名称:scala-rest-api-checksprojects,代码行数:50,代码来源:Secured.scala


示例5: basic644

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.fileupload.support

import com.google.common.base.Charsets
import com.google.common.io.BaseEncoding
import org.scalatest.Suite
import play.api.http.HeaderNames
import play.api.libs.ws.WSResponse
import uk.gov.hmrc.fileupload.{EnvelopeId, FileId, FileRefId}

trait FileActions extends ActionsSupport {
  this: Suite =>

  def basic644(s:String): String = {
    BaseEncoding.base64().encode(s.getBytes(Charsets.UTF_8))
  }

  def upload(data: Array[Byte], envelopeId: EnvelopeId, fileId: FileId, fileRefId: FileRefId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/$fileId/$fileRefId")
      .withHeaders("Content-Type" -> "application/octet-stream")
      .put(data)
      .futureValue

  def delete(envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/$fileId")
      .delete()
      .futureValue

  def download(envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/$fileId/content").withHeaders(HeaderNames.AUTHORIZATION -> ("Basic " + basic644("yuan:yaunspassword")))
      .get()
      .futureValue

  def updateFileMetadata(data: String, envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/$fileId/metadata" )
      .withHeaders("Content-Type" -> "application/json")
      .put(data.getBytes)
      .futureValue

  def getFileMetadataFor(envelopeId: EnvelopeId, fileId: FileId): WSResponse =
    client
      .url(s"$url/envelopes/$envelopeId/files/$fileId/metadata")
      .get()
      .futureValue

  def downloadEnvelope(envelopeId: EnvelopeId): WSResponse =
    client
      .url(s"$fileTransferUrl/envelopes/$envelopeId")
      .get()
      .futureValue
} 
开发者ID:hmrc,项目名称:file-upload-nos3,代码行数:55,代码来源:FileActions.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala UserService类代码示例发布时间:2022-05-23
下一篇:
Scala AvatarService类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap