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

Scala MalformedURLException类代码示例

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

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



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

示例1: ElasticDownloadUrlUtils

//设置package包名称以及导入依赖的类
package io.grhodes.sbt.elasticsearch

import java.net.{MalformedURLException, URL}

import org.apache.commons.lang3.StringUtils

private[elasticsearch] object ElasticDownloadUrlUtils {

  private val URLS = Map(
    "1." -> "https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-{VERSION}.zip",
    "2." -> "https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/{VERSION}/elasticsearch-{VERSION}.zip",
    "5." -> "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{VERSION}.zip"
  )

  def urlFromVersion(elasticVersion: String) = {
    val elsDownloadUrl = URLS.collectFirst {
      case (prefix, url) if elasticVersion.startsWith(prefix) => url
    }.getOrElse {
      throw new IllegalArgumentException("Invalid version: " + elasticVersion)
    }

    try {
      new URL(StringUtils.replace(elsDownloadUrl, "{VERSION}", elasticVersion))
    } catch {
      case e: MalformedURLException => throw new RuntimeException(e)
    }
  }

} 
开发者ID:grahamar,项目名称:sbt-elasticsearch,代码行数:30,代码来源:ElasticDownloadUrlUtils.scala


示例2: InlineKeyboard

//设置package包名称以及导入依赖的类
package ru.finagram.api

import java.net.{ MalformedURLException, URL }

import scala.collection.mutable

class InlineKeyboard {

  private val keyboards = mutable.Buffer[Seq[InlineKeyboardButton]]()

  @throws(clazz = classOf[MalformedURLException])
  def buttons(row: (String, Any)*): InlineKeyboard = {
    buttons(row.map(buttonFromTuple))
  }

  def buttons(row: => Seq[InlineKeyboardButton]): InlineKeyboard = {
    keyboards += row
    this
  }

  def create(): InlineKeyboardMarkup = {
    InlineKeyboardMarkup(keyboards.map(btn => btn))
  }

  def createOpt(): Option[InlineKeyboardMarkup] = Some(create())

  @throws(clazz = classOf[MalformedURLException])
  private def buttonFromTuple(tuple: (String, Any)): InlineKeyboardButton = {
    val text = tuple._1
    val data = tuple._2.toString
    val answer = data.toLowerCase
    // FIXME replace to Try(new URL)
    if (answer.startsWith("http://") || answer.startsWith("https://")) {
      InlineUrlKeyboardButton(text, data)
    } else {
      InlineCallbackKeyboardButton(text, data)
    }
  }
}

object InlineKeyboard {

  @throws(clazz = classOf[MalformedURLException])
  def apply(row: (String, Any)*): InlineKeyboardMarkup = {
    new InlineKeyboard()
      .buttons(row: _*)
      .create()
  }
} 
开发者ID:finagram,项目名称:finagram,代码行数:50,代码来源:InlineKeyboard.scala


示例3: UrlUtils

//设置package包名称以及导入依赖的类
package haishu.crawler.util

import java.net.{MalformedURLException, URL}

object UrlUtils {

  def canonicalizeUrl(base: URL, relUrl: String): URL = {
    // workaround: java resolves '//path/file + ?foo' to '//path/?foo', not '//path/file?foo' as desired
    val relUrl2 = if (relUrl.startsWith("?")) base.getPath + relUrl else relUrl
    // workaround: //example.com + ./foo = //example.com/./foo, not //example.com/foo
    val base2 =
      if (relUrl2.indexOf('.') == 0 && base.getFile.indexOf('/') != 0)
        new URL(base.getProtocol, base.getHost, base.getPort, "/" + base.getFile)
      else
        base

    new URL(base2, relUrl2)
  }

  // Borrowed from Jsoup
  def canonicalizeUrl(baseUrl: String, relUrl: String): String = {
    var base: URL = null
    try {
      try
        base = new URL(baseUrl)
      catch {
        case e: MalformedURLException =>
          // the base is unsuitable, but the attribute/rel may be abs on its own, so try that
          val abs = new URL(relUrl)
          return abs.toExternalForm
      }
      encodeIllegalCharacterInUrl(canonicalizeUrl(base, relUrl).toExternalForm)
    } catch {
      case e: MalformedURLException => ""
    }
  }

  def encodeIllegalCharacterInUrl(url: String): String = {
    //TODO more charator support
    url.replace(" ", "%20")
  }

} 
开发者ID:hualongdata,项目名称:hl-crawler,代码行数:44,代码来源:UrlUtils.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala RootJsonFormat类代码示例发布时间:2022-05-23
下一篇:
Scala PlaySpecification类代码示例发布时间: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