Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeflaterBijection #108

Open
sritchie opened this issue Apr 14, 2013 · 1 comment
Open

DeflaterBijection #108

sritchie opened this issue Apr 14, 2013 · 1 comment

Comments

@sritchie
Copy link
Collaborator

Bijection that moves between deflated and inflated bytes.

Here's the idea (please forgive my lack of wrapper classes):

import java.util.zip.{ Deflater, Inflater, InflaterInputStream, DeflaterOutputStream }
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream }

class DeflaterBijection(deflater: Deflater, inflater: Inflater) extends AbstractBijection[Array[Byte], Array[Byte]] {
  def apply(bytes: Array[Byte]) = {
    val baos = new ByteArrayOutputStream
    val dos = new DeflaterOutputStream(baos, deflater)
    dos.write(bytes)
    dos.close
    baos.toByteArray
  }
  override def invert(bytes: Array[Byte]) = {
    val baos = new ByteArrayOutputStream
    StreamUtils.copy(new InflaterInputStream(new ByteArrayInputStream(bytes), inflater), baos)
    baos.toByteArray
  }
}
@johnynek
Copy link
Collaborator

Looks fine, but I think we should wrap this:

https://github.com/dain/snappy/tree/master/src/main/java/org/iq80/snappy

Much better performance (much faster), pure Java, Apache license. We should encourage using snappy when we want performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants