本文整理汇总了Scala中java.net.URISyntaxException类的典型用法代码示例。如果您正苦于以下问题:Scala URISyntaxException类的具体用法?Scala URISyntaxException怎么用?Scala URISyntaxException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URISyntaxException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: BrokerInfo
//设置package包名称以及导入依赖的类
package com.godatadriven.kafka.offset
import java.net.{URI, URISyntaxException}
class BrokerInfo(private[this] val endpoints: Array[String],
private[this] val host: String,
private[this] val port: Int) {
private[this] def firstEndpointUri: Option[URI] = {
if (endpoints == null) {
return None
}
endpoints.headOption.flatMap { endpoint =>
try {
Some(new URI(endpoint))
} catch {
case _: URISyntaxException => None
}
}
}
def getHost: String = {
if (host == null || host.isEmpty) {
firstEndpointUri.head.getHost
} else {
host
}
}
def getPort: Int = {
if (port == -1) {
firstEndpointUri.head.getPort
} else {
port
}
}
}
示例2: RedirectUrlSanitizer
//设置package包名称以及导入依赖的类
package org.kneelawk.simplecursemodpackdownloader.net
import org.apache.http.impl.client.DefaultRedirectStrategy
import java.net.URI
import org.apache.http.client.utils.URIBuilder
import org.apache.http.ProtocolException
import java.net.URISyntaxException
import java.util.Locale
import org.apache.http.util.TextUtils
class RedirectUrlSanitizer extends DefaultRedirectStrategy {
override def createLocationURI(location: String): URI = {
try {
val b = new URIBuilder(URIUtil.sanitizeUri(location, true).normalize())
val host = b.getHost
if (host != null) {
b.setHost(host.toLowerCase(Locale.ROOT))
}
val path = b.getPath
if (TextUtils.isEmpty(path)) {
b.setPath("/")
}
val uri = b.build()
// Potential degugging point?
uri
} catch {
case ex: URISyntaxException => {
throw new ProtocolException(s"Invalid redirect URI: $location", ex)
}
}
}
}
示例3: ConfigProperties
//设置package包名称以及导入依赖的类
package org.stanoq.crawler.model
import java.net.{URI, URISyntaxException, URL}
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json.{DefaultJsonProtocol, RootJsonFormat}
import scala.util.Try
case class ConfigProperties(url:String, depthLimit:Int, timeout:Long=5, exclusions:List[String]=List(",")) {
require(url != null, "Config wasn't properly set!")
def validate = {
if (depthLimit <0) false
else if (timeout <0) false
else if (url.equals("")) false
else if (Try(new URL(url).getContent).isFailure) false
else true
}
def getUrl: String = url
def getDomain: String = {
try {return new URI(getUrl).getHost}
catch {case e: URISyntaxException => return null}
}
def getExclusions: List[String] = exclusions
}
case class Node(id: String, label:String, statusCode:Int )
case class Link(source: String, target:String)
case class CrawlerResponse(pages: List[Node], links: List[Link])
trait CrawlerProtocols extends SprayJsonSupport with DefaultJsonProtocol {
implicit val pageFormat: RootJsonFormat[Page] = jsonFormat3(Page.apply)
implicit val configFormat: RootJsonFormat[ConfigProperties] = jsonFormat4(ConfigProperties.apply)
implicit val nodeFormat: RootJsonFormat[Node] = jsonFormat3(Node.apply)
implicit val linkFormat: RootJsonFormat[Link] = jsonFormat2(Link.apply)
implicit val crawlerResponseFormat: RootJsonFormat[CrawlerResponse] = jsonFormat2(CrawlerResponse.apply)
}
示例4: Register
//设置package包名称以及导入依赖的类
package models
import java.net.{URI, URISyntaxException}
import play.api.libs.functional.syntax._
import play.api.libs.json._
case class Register(id: String, uri: URI)
object Register {
implicit val uriReads = Reads { js =>
js match {
case JsString(s) => try {
JsSuccess(new URI(s))
} catch {
case e: URISyntaxException => JsError(s"Unable to parse URI: ${e.getMessage}")
}
case _ => JsError("JsString expected to convert to URI")
}
}
implicit val registerReads: Reads[Register] = (
(JsPath \ "id").read[String] and
(JsPath \ "uri").read[URI]
) (Register.apply _)
}