本文整理汇总了Scala中java.net.URLDecoder类的典型用法代码示例。如果您正苦于以下问题:Scala URLDecoder类的具体用法?Scala URLDecoder怎么用?Scala URLDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URLDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Main
//设置package包名称以及导入依赖的类
package hu.blackbelt.cd.bintray.deploy
import java.net.URLDecoder
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.events.S3Event
import com.typesafe.scalalogging.LazyLogging
import scala.collection.JavaConverters._
class Main(context: Context) extends LazyLogging {
private def decodeS3Key(key: String): String = URLDecoder.decode(key.replace("+", " "), "utf-8")
def deploy(event: S3Event) = {
event.getRecords.asScala.foreach(
s3EventRecord => {
val bucket = s3EventRecord.getS3.getBucket.getName
val key = decodeS3Key(s3EventRecord.getS3.getObject.getKey)
val loc = StorageLocation(bucket, key)
logger.info(s"received event for $loc")
val parts = key.split('/')
require(parts.size > 1, s"cannot extract project name and version from $key")
val project = parts(0)
val version = parts(1)
val deployer = new Deploy(Project(loc, project, version))
logger.info(s"fetching $loc")
val archive = deployer.fetch {
is => {
logger.info("fetched")
logger.info("starting deployment to bintray")
deployer.upload(is).failed.toOption.foreach(throw _)
logger.info("deployment success")
}
}
}
)
}
}
示例2: disableUi
//设置package包名称以及导入依赖的类
package net.ruippeixotog.scalafbp.http
import java.net.URLDecoder
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.model.Uri
import akka.http.scaladsl.model.Uri.Query
import akka.http.scaladsl.server.Directives._
import spray.json.DefaultJsonProtocol._
import spray.json._
trait UiHttpService {
def disableUi: Boolean
private[this] val dummyUser = "user"
private[this] val dummyUserName = "ScalaFBP Development Environment"
private[this] val dummyToken = "oauthToken"
// format: OFF
lazy val uiRoutes =
if(disableUi) reject
else {
pathPrefix("oauth") {
path("login" / "oauth" / "authorize") {
parameter("redirect_uri") { encodedUri =>
val uri = Uri(URLDecoder.decode(encodedUri, "UTF-8"))
redirect(uri.withQuery(Query("code" -> dummyUser)), Found)
}
} ~
path("authenticate" / dummyUser) {
complete(Map("token" -> dummyToken))
} ~
path("user") {
complete(JsObject(
"name" -> JsString(dummyUserName),
"github" -> JsObject.empty))
}
} ~
pathEndOrSingleSlash { getFromResource("ui/index.html") } ~
getFromResourceDirectory("ui")
}
// format: ON
}
示例3: DoobieHelpers
//设置package包名称以及导入依赖的类
package com.imageintelligence.pix.repository
import java.net.{URL, URLDecoder}
import java.time.Instant
import doobie.imports._
object DoobieHelpers {
implicit val URLMeta: Meta[URL] =
Meta[String].nxmap(
i => new URL(i),
i => URLDecoder.decode(i.toString, "UTF-8")
)
implicit val InstantMeta: Meta[Instant] =
Meta[java.sql.Timestamp].nxmap(
i => i.toInstant,
i => new java.sql.Timestamp(i.toEpochMilli)
)
}
示例4: getImageType
//设置package包名称以及导入依赖的类
package org.aj.awslambda
import java.awt.image.BufferedImage
import java.io.IOException
import java.net.URLDecoder
import com.amazonaws.services.lambda.runtime.events.S3Event
import java.util.regex.Pattern
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
private def getImageType(srcKey: String): Option[String] = {
val matcher = Pattern.compile(".*\\.([^\\.]*)").matcher(srcKey)
matcher.matches() match {
case true => {
//get source image type and validate
val imageType = matcher.group(1)
imageTypes.get(imageType) match {
case Some(_) => Some(imageType)
case _ => None
}
}
case _ => None
}
}
private def decodeS3Key(key: String): String = URLDecoder.decode(key.replace("+", " "), "utf-8")
private def process(srcBucket: String, srcKey: String, imageType: String, dstBucket: String): Future[List[Url]] = {
//get source image with it's sizes
val sourceImage: (BufferedImage, Url) = getImage(srcBucket, srcKey)
//re-size
val original: Future[Url] = process(sourceImage._1, sourceImage._2, imageType, dstBucket, srcKey)
val resized: List[Option[Future[Url]]] = sizes.map { size =>
if (sourceImage._2.width != size) Some(process(sourceImage._1, size, imageType, dstBucket, srcKey))
else None
}
//return
Future.sequence(original :: resized.flatten)
}
}
示例5: createTempDir
//设置package包名称以及导入依赖的类
package eu.shiftforward.apso
import java.net.URLDecoder
import java.io.{ File, InputStream }
trait TestHelper {
def createTempDir(prefix: String = "logs", suffix: String = ""): File = {
val temp = File.createTempFile(prefix, suffix)
temp.delete()
temp.mkdir()
temp.deleteOnExit()
temp
}
@deprecated("Use `eu.shiftforward.apso.io.ResourceUtil.getResourceURL` instead where the " +
"`resource` argument is already prefixed with a '/'", "2016/05/24")
def getResourceURL(resource: String): String =
URLDecoder.decode(getClass.getResource(resource).getFile, "UTF-8")
@deprecated("Use `eu.shiftforward.apso.io.ResourceUtil.getResourceStream` instead where the " +
"`resource` argument is already prefixed with a '/'", "2016/05/24")
def getResourceStream(resource: String): InputStream =
getClass.getResourceAsStream(resource)
}
示例6: HardCodedGroundTruthImportTest
//设置package包名称以及导入依赖的类
package org.opencompare.io.wikipedia
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
import org.opencompare.api.java.impl.PCMFactoryImpl
import org.opencompare.io.wikipedia.io.{WikiTextTemplateProcessor, WikiTextLoader, MediaWikiAPI}
import org.scalatest.{Matchers, FlatSpec}
class HardCodedGroundTruthImportTest extends FlatSpec with Matchers {
val pcmFactory = new PCMFactoryImpl
val url = "wikipedia.org"
val mediaWikiAPI = new MediaWikiAPI(url)
val miner = new WikiTextLoader(new WikiTextTemplateProcessor(mediaWikiAPI))
it should "import a PCM with special characters or nested tables (don't remember what the test is supposed to do)" in {
val language = "ja"
val title = "%E6%A0%83%E6%9C%A8%E7%9C%8C"
val decodedTitle = URLDecoder.decode(title, StandardCharsets.UTF_8.name)
val wikitext = mediaWikiAPI.getWikitextFromTitle(language, decodedTitle)
val pcms = miner.mine(language, wikitext, title)
pcms.size() shouldNot be (0)
}
}
示例7: NowPlaying
//设置package包名称以及导入依赖的类
import java.io.File
import java.net.URLDecoder
import scala.sys.process.{ Process, ProcessIO }
import scala.io.Source
object NowPlaying {
def main(args: Array[String]): Unit = {
val processBuilder = Process("qdbus-qt5 org.mpris.MediaPlayer2.audacious /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata")
val processIo = new ProcessIO(
_ => (),
stdout => {
val wantedLines = Source.fromInputStream(stdout).getLines().map { line =>
val values = line.split(": ")
if(values.length > 0) {
(values(0), values.drop(1).foldLeft("")((x, y) => x + y))
} else {
("", "")
}
}.toMap.filter(x => x._1 == "xesam:title" || x._1 == "xesam:artist" || x._1 == "xesam:url")
val nowPlayingResult = NowPlayingResult(wantedLines.get("xesam:title"), wantedLines.get("xesam:artist"), wantedLines.get("xesam:url"))
nowPlayingResult match {
case NowPlayingResult(None, None, url) => {
val filename = new File(url.get).getName
val decodedFilename = URLDecoder.decode(filename, "UTF-8")
println(s"/me is playing $decodedFilename")
}
case NowPlayingResult(title, artist, _) => println(s"/me is playing ${artist.get} - ${title.get}")
case _ => println("/me is playing I have no idea")
}
},
_ => ()
)
processBuilder.run(processIo)
}
}
case class NowPlayingResult(title: Option[String], artist: Option[String], absolutePath: Option[String])
示例8: DoobieHelpers
//设置package包名称以及导入依赖的类
package me.davidvuong.http_api.helpers
import java.net.{URL, URLDecoder}
import java.time.Instant
import doobie.imports._
import me.davidvuong.http_api.domain.MessageStatus
object DoobieHelpers {
implicit val URLMeta: Meta[URL] =
Meta[String].nxmap(
i => new URL(i),
i => URLDecoder.decode(i.toString, "UTF-8")
)
implicit val InstantMeta: Meta[Instant] =
Meta[java.sql.Timestamp].nxmap(
i => i.toInstant,
i => new java.sql.Timestamp(i.toEpochMilli)
)
implicit val MessageStatusMeta2: Meta[MessageStatus] =
Meta[String].nxmap(
i => MessageStatus.fromString(i).fold(sys.error, identity),
i => MessageStatus.toString(i)
)
}
示例9: ELBSSLCertificateLambdaConfig
//设置package包名称以及导入依赖的类
package com.ocelotconsulting
import java.net.URLDecoder
import com.amazonaws.services.s3.event.S3EventNotification.S3Entity
import com.typesafe.config.{Config, ConfigFactory}
import scala.collection.JavaConverters._
import scala.language.postfixOps
package object ssl {
object ELBSSLCertificateLambdaConfig {
val config = ConfigFactory.load()
val certInfo: Iterable[Config] = config.getConfigList("cert-path-to-arn") asScala
private def forS3Event(s3Path: String): Config = certInfo.filter { _.getString("s3") == s3Path} head
def arn(s3Path: String) = forS3Event(s3Path).getString("arn")
def elb(s3Path: String) = forS3Event(s3Path).getString("elb")
}
def toSSLCertName(entity: S3Entity): String =
ELBSSLCertificateLambdaConfig.arn(s"${decodeS3Key(entity.getBucket.getName)}/${decodeS3Key(entity.getObject.getKey)}")
def toELBName(entity: S3Entity): String =
ELBSSLCertificateLambdaConfig.elb(s"${decodeS3Key(entity.getBucket.getName)}/${decodeS3Key(entity.getObject.getKey)}")
def decodeS3Key(key: String): String = URLDecoder.decode(key.replace("+", " "), "utf-8")
}
示例10: PlainQueryConverter
//设置package包名称以及导入依赖的类
package com.hypertino.hyperbus.model.hrl
import java.net.{URLDecoder, URLEncoder}
import com.hypertino.binders.value.{Null, Obj, Text, Value}
object PlainQueryConverter extends QueryConverter {
final val encoding = "UTF-8"
override def parseQueryString(queryString: String): Value = {
if (queryString == null || queryString.isEmpty) {
Null
} else {
Obj(queryString.split('&').map { s ?
val i = s.indexOf('=')
if (i>0) {
val left = s.substring(0, i)
val right = Text(URLDecoder.decode(s.substring(i+1), encoding))
left ? right
}
else {
s ? Null
}
}.toMap)
}
}
override def toQueryString(value: Value): String = {
value match {
case Null ? ""
case Text(s) ? s
case Obj(elements) ? elements.map { case (k, v) ?
if (v.isNull) {
k
}
else {
k + "=" + URLEncoder.encode(v.toString, encoding)
}
} mkString "&"
case other ? throw new IllegalArgumentException(s"$other is not an Obj or Text")
}
}
}
示例11: Main
//设置package包名称以及导入依赖的类
package net.nocono
import java.io.{ InputStream, OutputStream }
import java.net.URLDecoder
import com.fasterxml.jackson.databind.{ DeserializationFeature, ObjectMapper }
import com.fasterxml.jackson.module.scala.DefaultScalaModule
class Main {
val scalaMapper = new ObjectMapper().registerModule(new DefaultScalaModule).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
def handler(input: InputStream, output: OutputStream): Unit = {
val params = scalaMapper.readValue(input, classOf[SlackOutgoingData])
println(params)
val result = params.decodedText match {
case "?????" => Some(s"?????, ${params.user_name}")
case "Scala" => Some("?????")
case _ => None
}
result.foreach { r =>
output.write( s"""{ "text": "$r" }""".getBytes("UTF-8"))
}
}
}
case class SlackOutgoingData(
token: String,
team_id: String,
team_domain: String,
service_id: String,
channel_id: String,
channel_name: String,
timestamp: String,
user_id: String,
user_name: String,
text: String,
trigger_word: String) {
val decodedText = URLDecoder.decode(text, "UTF-8")
}
示例12: Binders
//设置package包名称以及导入依赖的类
package support
import events._
import eventstore.{ StoreRevision, StreamRevision }
import java.net.URLDecoder
import java.util.UUID
object Binders {
implicit def IdentifierPathBindable[A <: Identifier](implicit companion: IdentifierCompanion[A]) = new play.api.mvc.PathBindable[A] {
override def bind(key: String, value: String) = try {
Right(companion.apply(UUID.fromString(URLDecoder.decode(value, "utf-8"))))
} catch {
case _: RuntimeException => Left(s"Cannot parse parameter $key as ${companion.prefix}: ${URLDecoder.decode(value, "utf-8")}")
}
override def unbind(key: String, value: A) = value.uuid.toString
}
implicit object CommentIdBindable extends play.api.mvc.PathBindable[CommentId] {
override def bind(key: String, value: String) = try {
Right(CommentId(URLDecoder.decode(value, "utf-8").toInt))
} catch {
case _: RuntimeException => Left(s"Cannot parse parameter $key as CommentId: ${URLDecoder.decode(value, "utf-8")}")
}
override def unbind(key: String, value: CommentId) = value.value.toString
}
implicit object queryStringBindableStoreRevision extends play.api.mvc.QueryStringBindable[StoreRevision] {
override def bind(key: String, params: Map[String, Seq[String]]) = params.get(key).flatMap(_.headOption).map { value =>
try {
Right(StoreRevision(value.toLong))
} catch {
case _: RuntimeException => Left(s"Cannot parse parameter $key as StoreRevision: $value")
}
}
override def unbind(key: String, value: StoreRevision) = s"$key=${value.value}"
}
implicit object queryStringBindableStreamRevision extends play.api.mvc.QueryStringBindable[StreamRevision] {
override def bind(key: String, params: Map[String, Seq[String]]) = params.get(key).flatMap(_.headOption).map { value =>
try {
Right(StreamRevision(value.toLong))
} catch {
case _: RuntimeException => Left(s"Cannot parse parameter $key as StreamRevision: $value")
}
}
override def unbind(key: String, value: StreamRevision) = s"$key=${value.value}"
}
}
示例13: Paths
//设置package包名称以及导入依赖的类
package myscala.util
import java.io.File
import java.net.{URL, URLDecoder}
import myscala._
import myscala.io.Resource
object Paths {
def urlAsFile(url: URL): File = {
if (url == null) return null
new File(urlAsPath(url))
}
def urlAsPath(url: URL): String = {
if (url == null) {
return null
}
val protocol = url.getProtocol
var file = url.getPath
file = URLDecoder.decode(file, "UTF8")
if (Resource.URL_PROTOCOL_FILE == protocol) {
return file
}
else if (Resource.URL_PROTOCOL_JAR == protocol || Resource.URL_PROTOCOL_ZIP == protocol) {
val ipos = file.indexOf(Resource.URL_SEPARATOR_JAR)
if (ipos > 0) file = file.substring(0, ipos)
if (file.startsWith(Resource.URL_PREFIX_FILE)) file = file.substring(Resource.URL_PREFIX_FILE.length)
return file
}
else if (Resource.URL_PROTOCOL_VFS == protocol) {
val ipos = file.indexOf(Resource.URL_SEPARATOR_JAR)
if (ipos > 0) file = file.substring(0, ipos)
else if (file.endsWith("/")) file = file.substring(0, file.length - 1)
return file
}
file
}
def removeStart(path: String, remove: String): String = path.stripStart(remove)
def removeEnd(path: String, remove: String): String = path.stripEnd(remove)
}
示例14: Main
//设置package包名称以及导入依赖的类
package com.iheart.lambda
import java.net.URLDecoder
import com.iheart.lambda.Utils._
import play.api.libs.ws.WSResponse
import play.api.libs.ws.ning.NingWSClient
import scala.collection.JavaConverters._
import com.amazonaws.services.lambda.runtime.events.S3Event
import com.amazonaws.services.lambda.runtime.Context
import scala.concurrent.{Future, Await}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
class Main {
val wsClient = NingWSClient()
def handleEvent(event: S3Event, context: Context) = {
event.getRecords.asScala.foreach { record =>
val bucket = record.getS3.getBucket.getName
val key = URLDecoder.decode(record.getS3.getObject.getKey,"UTF-8")
println("Received key " + key)
sendToNewRelic(parseLogFile(bucket,key))
}
}
}
示例15: lurlDecode
//设置package包名称以及导入依赖的类
package com.levent.hive.udfs
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF
import java.net.URLDecoder
@Description(
name = "lurlDecode",
value = "_FUNC_(string) URLDecode - decodes application/x-www-form-urlencoded type into string (UTF-8)",
extended = "SELECT lurlDecode(string) FROM test LIMIT 1;")
class lurlDecode extends UDF {
def evaluate(url: String ): String= {
if (url == null )
return null
val decodedURL= java.net.URLDecoder.decode(url, "UTF-8");
return (decodedURL)
}
}