All Downloads are FREE. Search and download functionalities are using the official Maven repository.

util.IDN.scala Maven / Gradle / Ivy

There is a newer version: 0.13.4
Show newest version
package dispatch

import java.net.IDN
import java.lang.IllegalArgumentException

// This will be thrown if the conversion from an IDN domain to the pure-ascii form
// fails. Otherwise, the exception that is caused will be thrown.
case class InternationalDomainConversionException(
  message: String,
  cause: IllegalArgumentException
) extends Exception(message, cause)

object IDNDomainHelpers {

  def safeConvert(domain: String): String = {
    try {
      IDN.toASCII(domain)
    } catch {
      case error: IllegalArgumentException =>
        throw InternationalDomainConversionException(
          "Error converting domain name to ASCII",
          error
        )
      case error: Throwable => throw error
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy