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

com.avsystem.commons.serialization.Base64.scala Maven / Gradle / Ivy

There is a newer version: 2.22.0
Show newest version
package com.avsystem.commons
package serialization

import java.util.{Base64 => JBase64}

object Base64 {
  def encode(bytes: Array[Byte], withoutPadding: Boolean = false, urlSafe: Boolean = false): String = {
    val encoder = (if (urlSafe) JBase64.getUrlEncoder else JBase64.getEncoder) |>
      (e => if (withoutPadding) e.withoutPadding else e)
    encoder.encodeToString(bytes)
  }

  def decode(base64: String, urlSafe: Boolean = false): Array[Byte] = {
    val decoder = if (urlSafe) JBase64.getUrlDecoder else JBase64.getDecoder
    decoder.decode(base64)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy