本文整理汇总了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
}
}
示例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())
}
示例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)
}