Skip to content

Commit

Permalink
Merge pull request #95 from databricks/add-xz-std-function
Browse files Browse the repository at this point in the history
Refactored JVM Platform Code
  • Loading branch information
lihaoyi-databricks authored Sep 25, 2020
2 parents cca3625 + d66e7ab commit 5ccdb4c
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions sjsonnet/src-jvm/sjsonnet/Platform.scala
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
package sjsonnet

import java.io.ByteArrayOutputStream
import java.util.Base64
import java.util.zip.GZIPOutputStream
import org.tukaani.xz.LZMA2Options
import org.tukaani.xz.XZOutputStream

object Platform {
def gzipBytes(b: Array[Byte]): String = {
val outputStream = new java.io.ByteArrayOutputStream(b.length)
val gzip = new java.util.zip.GZIPOutputStream(outputStream)
val outputStream: ByteArrayOutputStream = new ByteArrayOutputStream(b.length)
val gzip: GZIPOutputStream = new GZIPOutputStream(outputStream)
gzip.write(b)
gzip.close()
val gzippedBase64: String = java.util.Base64.getEncoder.encodeToString(outputStream.toByteArray)
val gzippedBase64: String = Base64.getEncoder.encodeToString(outputStream.toByteArray)
outputStream.close()
gzippedBase64
}
def gzipString(s: String): String = {
val outputStream = new java.io.ByteArrayOutputStream(s.length)
val gzip = new java.util.zip.GZIPOutputStream(outputStream)
gzip.write(s.getBytes())
gzip.close()
val gzippedBase64: String = java.util.Base64.getEncoder.encodeToString(outputStream.toByteArray)
outputStream.close()
gzippedBase64
gzipBytes(s.getBytes())
}
def xzBytes(b: Array[Byte]): String = {
val outputStream = new java.io.ByteArrayOutputStream(b.length)
val gzip = new org.tukaani.xz.XZOutputStream(outputStream, new org.tukaani.xz.LZMA2Options())
gzip.write(b)
gzip.close()
val xzedBase64: String = java.util.Base64.getEncoder.encodeToString(outputStream.toByteArray)
val outputStream: ByteArrayOutputStream = new ByteArrayOutputStream(b.length)
val xz: XZOutputStream = new XZOutputStream(outputStream, new LZMA2Options())
xz.write(b)
xz.close()
val xzedBase64: String = Base64.getEncoder.encodeToString(outputStream.toByteArray)
outputStream.close()
xzedBase64
}
def xzString(s: String): String = {
val outputStream = new java.io.ByteArrayOutputStream(s.length)
val gzip = new org.tukaani.xz.XZOutputStream(outputStream, new org.tukaani.xz.LZMA2Options())
gzip.write(s.getBytes())
gzip.close()
val xzedBase64: String = java.util.Base64.getEncoder.encodeToString(outputStream.toByteArray)
outputStream.close()
xzedBase64
xzBytes(s.getBytes())
}
def md5(s: String): String = {
java.security.MessageDigest.getInstance("MD5")
Expand Down

0 comments on commit 5ccdb4c

Please sign in to comment.