本文整理汇总了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
}
}
}
开发者ID:godatadriven,项目名称:prometheus-kafka-offsets,代码行数:39,代码来源:BrokerInfo.scala
示例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)
}
}
}
}
开发者ID:Kneelawk,项目名称:SimpleCurseModpackDownloader,代码行数:33,代码来源:RedirectUrlSanitizer.scala
示例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)
}
开发者ID:olka,项目名称:stanoq,代码行数:41,代码来源:ConfigProperties.scala
示例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 _)
}
开发者ID:kuhnuri,项目名称:kuhnuri-queue,代码行数:28,代码来源:Register.scala
注:本文中的java.net.URISyntaxException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论