• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala GZIPOutputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Codec

//设置package包名称以及导入依赖的类
package at.hazm.quebic

import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream, OutputStream}
import java.util.zip.{GZIPInputStream, GZIPOutputStream}

import scala.annotation.tailrec

sealed abstract class Codec(val id:Byte, val name:String) extends Type {
  def encode(buffer:Array[Byte]):Array[Byte]

  def decode(buffer:Array[Byte]):Array[Byte]
}

object Codec {
  val values:Seq[Codec] = Seq(PLAIN, GZIP)
  private[this] val valuesMap = values.groupBy(_.id).mapValues(_.head)

  def valueOf(id:Byte):Codec = valuesMap(id)

  case object PLAIN extends Codec(0, "plain") {
    def encode(buffer:Array[Byte]):Array[Byte] = buffer

    def decode(buffer:Array[Byte]):Array[Byte] = buffer
  }

  case object GZIP extends Codec(1, "gzip") {
    def encode(buffer:Array[Byte]):Array[Byte] = {
      val baos = new ByteArrayOutputStream()
      val out = new GZIPOutputStream(baos)
      out.write(buffer)
      out.finish()
      out.finish()
      baos.toByteArray
    }

    def decode(buffer:Array[Byte]):Array[Byte] = {
      val in = new GZIPInputStream(new ByteArrayInputStream(buffer))
      val out = new ByteArrayOutputStream()
      _copy(in, out, new Array[Byte](2014))
      out.close()
      out.toByteArray
    }
  }

  @tailrec
  private[Codec] def _copy(in:InputStream, out:OutputStream, buffer:Array[Byte]):Unit = {
    val len = in.read(buffer)
    if(len > 0) {
      out.write(buffer, 0, len)
      _copy(in, out, buffer)
    }
  }

} 
开发者ID:torao,项目名称:quebic,代码行数:55,代码来源:Codec.scala


示例2: Zip

//设置package包名称以及导入依赖的类
package se.joham.funrts.util

import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.util.zip.{GZIPInputStream, GZIPOutputStream}

import com.google.common.io.ByteStreams


object Zip {

  def compress(bytes: Array[Byte]): Array[Byte] = {
    val bos = new ByteArrayOutputStream()
    val zs = new GZIPOutputStream(bos)
    zs.write(bytes)
    zs.close()
    bos.toByteArray
  }

  def decompress(bytes: Array[Byte]): Array[Byte] = {
    val bis = new ByteArrayInputStream(bytes)
    val zs = new GZIPInputStream(bis)
    ByteStreams.toByteArray(zs)
  }

} 
开发者ID:GiGurra,项目名称:fun-rts,代码行数:26,代码来源:Zip.scala


示例3: GZipServletOutputStream

//设置package包名称以及导入依赖的类
package co.informatica.mvc.filters

import java.io.{IOException, OutputStream}
import java.util.zip.GZIPOutputStream
import javax.servlet.{ServletOutputStream, WriteListener}

class GZipServletOutputStream @throws[IOException]
(val output: OutputStream) extends ServletOutputStream {
  private val gzipOutputStream = new GZIPOutputStream(output)

  @throws[IOException]
  override def close(): Unit = {
    this.gzipOutputStream.close()
  }

  @throws[IOException]
  override def flush(): Unit = {
    this.gzipOutputStream.flush()
  }

  @throws[IOException]
  override def write(b: Array[Byte]): Unit = {
    this.gzipOutputStream.write(b)
  }

  @throws[IOException]
  override def write(b: Array[Byte], off: Int, len: Int): Unit = {
    this.gzipOutputStream.write(b, off, len)
  }

  @throws[IOException]
  override def write(b: Int): Unit = {
    this.gzipOutputStream.write(b)
  }

  override def isReady: Boolean = ???

  override def setWriteListener(writeListener: WriteListener): Unit = {

  }
} 
开发者ID:jkevingutierrez,项目名称:MVC,代码行数:42,代码来源:GZipServletOutputStream.scala


示例4: CompressionUtils

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.commons.utils

import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.util.Base64
import java.util.zip.{GZIPInputStream, GZIPOutputStream}

import com.flipkart.connekt.commons.core.Wrappers._
import org.apache.commons.io.IOUtils

import scala.util.Try
import scala.util.control.NoStackTrace

object CompressionUtils {

  def inflate(deflatedTxt: String): Try[String] = Try_ {
    val bytes = Base64.getUrlDecoder.decode(deflatedTxt)
    try {
      val zipInputStream = new GZIPInputStream(new ByteArrayInputStream(bytes))
      IOUtils.toString(zipInputStream)
    } catch {
      case ex:java.util.zip.ZipException =>
        throw new Exception(ex.getMessage) with NoStackTrace
    }
  }

  def deflate(txt: String): Try[String] = Try_ {
    val arrOutputStream = new ByteArrayOutputStream()
    val zipOutputStream = new GZIPOutputStream(arrOutputStream)
    zipOutputStream.write(txt.getBytes)
    zipOutputStream.close()
    Base64.getUrlEncoder.encodeToString(arrOutputStream.toByteArray)
  }

  implicit class StringCompress(val s: String) {
    def compress: Try[String] = deflate(s)
    def decompress: Try[String] = inflate(s)
  }

} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:40,代码来源:CompressionUtils.scala


示例5: Configuration

//设置package包名称以及导入依赖的类
package com.outr.jefe.runner

import java.io.{File, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream}
import java.util.zip.{GZIPInputStream, GZIPOutputStream}

import com.outr.jefe.repo._

import scala.collection.mutable.ListBuffer

case class Configuration(dependency: VersionedDependency,
                         mainClass: String,
                         args: Array[String] = Array.empty,
                         vmArgs: Array[String] = Array.empty,
                         workingDirectory: File = new File("."),
                         showDialogIfPossible: Boolean = true,
                         repositories: Repositories = Repositories(),
                         newProcess: Boolean = false)

object Configuration {
  def load(file: File): Configuration = {
    val ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream(file)))
    try {
      ois.readObject().asInstanceOf[Configuration]
    } finally {
      ois.close()
    }
  }

  def save(configuration: Configuration, file: File): Unit = {
    Option(file.getParentFile).foreach(_.mkdirs())
    val oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(file)))
    try {
      oos.writeObject(configuration)
    } finally {
      oos.flush()
      oos.close()
    }
  }
}

case class Repositories(list: List[Repository] = List(Ivy2.Local, Maven.Repo1, Sonatype.Releases, Sonatype.Snapshots)) {
  def withMaven(name: String, url: String): Repositories = copy(list ::: List(MavenRepository(name, url)))
} 
开发者ID:outr,项目名称:jefe,代码行数:44,代码来源:Configuration.scala


示例6: Compressor

//设置package包名称以及导入依赖的类
package org.zalando.znap.utils

import java.io.{BufferedReader, ByteArrayInputStream, ByteArrayOutputStream, InputStreamReader}
import java.util.Base64
import java.util.zip.{GZIPInputStream, GZIPOutputStream}

import akka.http.impl.model.parser.Base64Parsing
import org.apache.commons.compress.utils.IOUtils

object Compressor {
  private val encoding = "UTF-8"

  private val base64Encoder = Base64.getEncoder
  private val base64Decoder = Base64.getDecoder

  def compress(string: String): Array[Byte] = {
    val baos = new ByteArrayOutputStream()
    val gos = new GZIPOutputStream(baos)
    gos.write(string.getBytes(encoding))
    gos.flush()
    baos.flush()
    IOUtils.closeQuietly(gos)
    IOUtils.closeQuietly(baos)
    baos.toByteArray
  }

  def compressBase64(string: String): String = {
    base64Encoder.encodeToString(compress(string))
  }

  def decompress(array: Array[Byte]): String = {
    val bais = new ByteArrayInputStream(array)
    val gis = new GZIPInputStream(bais)
    val result = new String(IOUtils.toByteArray(gis), encoding)
    IOUtils.closeQuietly(bais)
    IOUtils.closeQuietly(gis)
    result
  }

  def decompressBase64(base64String: String): String = {
    decompress(base64Decoder.decode(base64String))
  }
} 
开发者ID:fogfish,项目名称:znap,代码行数:44,代码来源:Compressor.scala


示例7: NoneType

//设置package包名称以及导入依赖的类
package com.gu.thrift.serializer

import java.io._
import java.util.zip.{GZIPInputStream, GZIPOutputStream}

import scala.annotation.tailrec

sealed trait CompressionType
case object NoneType extends CompressionType
case object GzipType extends CompressionType

object Compression {

  def gzip(data: Array[Byte]): Array[Byte] = {
    try {
        val bos = new ByteArrayOutputStream()
        val out = new GZIPOutputStream(bos)
        out.write(data)
        out.close()
        bos.toByteArray
    } catch {
      case e: IOException => throw new RuntimeException(e);
    }
  }

  def gunzip(data: Array[Byte]): Array[Byte] = {
    try {
      val bos = new ByteArrayOutputStream()
      val bis = new ByteArrayInputStream(data)
      val in = new GZIPInputStream(bis)
      copy(in, bos)
      in.close()
      bos.close()
      bos.toByteArray()
    } catch {
      case e: IOException => throw new RuntimeException(e);
    }
  }

  @tailrec
  private def copy(is: InputStream, os: OutputStream, bufferSize: Int = 1024) {
    val buffer = new Array[Byte](bufferSize)
    is.read(buffer, 0, buffer.length) match {
      case -1 => ()
      case n =>
        os.write(buffer, 0, n)
        copy(is, os, bufferSize)
    }
  }

} 
开发者ID:guardian,项目名称:thrift-serializer,代码行数:52,代码来源:Compression.scala


示例8: Zip

//设置package包名称以及导入依赖的类
package com.github.gigurra.compression

import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream}
import java.util.zip.{GZIPInputStream, GZIPOutputStream}


object Zip {

  def compress(bytes: Array[Byte]): Array[Byte] = {
    val bos = new ByteArrayOutputStream()
    val zs = new GZIPOutputStream(bos)
    zs.write(bytes)
    zs.close()
    bos.toByteArray
  }

  def decompress(bytes: Array[Byte]): Array[Byte] = {
    val bis = new ByteArrayInputStream(bytes)
    val zs = new GZIPInputStream(bis)
    toByteArray(zs)
  }

  private def toByteArray(in: InputStream): Array[Byte] = {
    val arr = new Array[Byte](in.available)
    in.read(arr)
    arr
  }
} 
开发者ID:GiGurra,项目名称:scala-libgurra,代码行数:29,代码来源:Zip.scala


示例9: encode

//设置package包名称以及导入依赖的类
package com.twitter.util

import com.twitter.io.StreamIO
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.nio.charset.{StandardCharsets => Charsets}
import java.util.Base64
import java.util.zip.{GZIPInputStream, GZIPOutputStream}


trait StringEncoder {
  def encode(bytes: Array[Byte]): String = new String(bytes)
  def decode(str: String): Array[Byte] = str.getBytes
}


trait GZIPStringEncoder extends StringEncoder {
  override def encode(bytes: Array[Byte]): String = {
    val baos = new ByteArrayOutputStream
    val gos = new GZIPOutputStream(baos)
    try {
      gos.write(bytes)
    } finally {
      gos.close()
    }
    Base64StringEncoder.encode(baos.toByteArray)
  }

  def encodeString(str: String) = encode(str.getBytes("UTF-8"))

  override def decode(str: String): Array[Byte] = {
    val baos = new ByteArrayOutputStream
    val gis = new GZIPInputStream(new ByteArrayInputStream(Base64StringEncoder.decode(str)))
    try {
      StreamIO.copy(gis, baos)
    } finally {
      gis.close()
    }

    baos.toByteArray
  }

  def decodeString(str: String): String = new String(decode(str), "UTF-8")
}

object GZIPStringEncoder extends GZIPStringEncoder 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:46,代码来源:StringEncoder.scala


示例10: Args

//设置package包名称以及导入依赖的类
package no.uit.sfb.args

import java.io._
import java.util.zip.{GZIPOutputStream, GZIPInputStream}
import com.beust.jcommander.Parameter



trait SqliteDatabaseFileArg {
  @Parameter(
    names = Array("-d" ,"--database"),
    description = "SQLite3 database file")
  var sqliteDatabaseFile: String = "annotations.sqlite3"
}

trait BatchSizeArg {
  @Parameter(
    names = Array("--batch-size"),
    description = "Number of items in write buffer")
  var batchSize = 10000
}

object Args {
  def parseInputFile(name: String): InputStream = {
    if(name == "-") System.in
    else {
      val fileStream = new FileInputStream(name)
      if(name.endsWith(".gz")) new GZIPInputStream(fileStream)
      else fileStream
    }
  }

  def lineReader(filename: String): BufferedReader = {
    new BufferedReader(new InputStreamReader(parseInputFile(filename)))
  }

  def lineWriter(filename: String): PrintStream = {
    new PrintStream(new BufferedOutputStream(parseOutputFile(filename)))
  }

  def parseOutputFile(name: String): OutputStream = {
    if(name == "-") System.out
    else {
      val fileStream = new FileOutputStream(name)
      if(name.endsWith(".gz")) new GZIPOutputStream(fileStream)
      else fileStream
    }
  }

  def parseTags(tags: String): List[String] = {
    tags.split(',').toList.filter(!_.isEmpty)
  }
} 
开发者ID:jarlebass,项目名称:combustio,代码行数:54,代码来源:Args.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala HashPartitioner类代码示例发布时间:2022-05-23
下一篇:
Scala X509Certificate类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap