本文整理汇总了Scala中play.utils.UriEncoding类的典型用法代码示例。如果您正苦于以下问题:Scala UriEncoding类的具体用法?Scala UriEncoding怎么用?Scala UriEncoding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UriEncoding类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: URIUtils
//设置package包名称以及导入依赖的类
package com.pygmalios.reactiveinflux.impl
import java.net.{URI, URLEncoder}
import com.google.common.base.Charsets
import play.utils.UriEncoding
object URIUtils {
private val sep = "/"
def appendPath(uri: URI, path: String): URI = {
val encodedPath = UriEncoding.encodePathSegment(path.stripPrefix(sep), Charsets.UTF_8.name())
new URI(uri.toString.stripSuffix(sep) + sep + encodedPath)
}
def appendQuery(uri: URI, qs: (String, String)*): URI =
new URI(uri.toString + queryToString(qs:_*))
def queryToString(qs: (String, String)*): String =
qs.map { case(k, v) =>
k + "=" + URLEncoder.encode(v, Charsets.UTF_8.name()).replaceAll(" ", "%20")
}.mkString(if (qs.isEmpty) "" else "?", "&", "")
}
示例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
}