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


Scala InetAddresses类代码示例

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


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

示例1: InetSocketAddressClass

//设置package包名称以及导入依赖的类
package com.bwsw.tstreamstransactionserver.netty

import com.google.common.net.InetAddresses

case class InetSocketAddressClass(address: String, port: Int){
  override def toString: String = s"/$address:$port"
}
object InetSocketAddressClass {
  def isValidSocketAddress(inetAddress: String, port: Int): Boolean = {
    val validHostname = scala.util.Try(java.net.InetAddress.getByName(inetAddress))
    if (
      port.toInt > 0 &&
        port.toInt < 65536 &&
        inetAddress != null &&
        (InetAddresses.isInetAddress(inetAddress) || validHostname.isSuccess)
    ) true
    else false
  }
} 
开发者ID:bwsw,项目名称:tstreams-transaction-server,代码行数:20,代码来源:InetSocketAddressClass.scala

示例2: net

//设置package包名称以及导入依赖的类
package refined.guava.net

import java.net.{Inet4Address, Inet6Address}

import com.google.common.net.{InetAddresses, InternetDomainName, MediaType}
import eu.timepit.refined.api.Validate
import refined.guava.net.net.{DNS, IP, IPv4, IPv6, Media}

object net extends NetValidate {
  case class IP()
  case class IPv4()
  case class IPv6()
  case class DNS()
  case class Media()
}

private[net] trait NetValidate {
  implicit def ipValidate: Validate.Plain[String, IP] =
    Validate.fromPartial(InetAddresses.forString, "IP Address", IP())

  implicit def ipv4Validate: Validate.Plain[String, IPv4] =
    Validate.fromPredicate(
      str => InetAddresses.forString(str).isInstanceOf[Inet4Address],
      str => s"$str is not an IPv4 Address",
      IPv4())

  implicit def ipv6Validate: Validate.Plain[String, IPv6] =
    Validate.fromPredicate(
      str => InetAddresses.forString(str).isInstanceOf[Inet6Address],
      str => s"$str is not an IPv6 Address",
      IPv6())


  implicit def dnsValidate: Validate.Plain[String, DNS] =
    Validate.fromPartial(InternetDomainName.from, "DNS name", DNS())

  implicit def mediaValidate: Validate.Plain[String, Media] =
    Validate.fromPartial(MediaType.parse, "MediaType", Media())

} 
开发者ID:derekmorr,项目名称:refined-guava,代码行数:41,代码来源:net.scala

示例3: InetAddressDeserializer

//设置package包名称以及导入依赖的类
package io.buoyant.config.types

import com.fasterxml.jackson.core.{JsonGenerator, JsonParser}
import com.fasterxml.jackson.databind.{SerializerProvider, DeserializationContext}
import com.google.common.net.InetAddresses
import io.buoyant.config.{ConfigSerializer, ConfigDeserializer}
import java.net.InetAddress

class InetAddressDeserializer extends ConfigDeserializer[InetAddress] {
  override def deserialize(jp: JsonParser, ctxt: DeserializationContext): InetAddress =
    catchMappingException(ctxt) {
      InetAddresses.forString(_parseString(jp, ctxt))
    }
}

class InetAddressSerializer extends ConfigSerializer[InetAddress] {
  override def serialize(
    value: InetAddress,
    jgen: JsonGenerator,
    provider: SerializerProvider
  ): Unit = jgen.writeString(value.getHostName)
} 
开发者ID:linkerd,项目名称:linkerd,代码行数:23,代码来源:InetAddressDeserializer.scala


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