当前位置: 首页>>代码示例>>Scala>>正文


Scala MalformedURLException类代码示例

本文整理汇总了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;未经允许,请勿转载。