bijection
bijection copied to clipboard
DeflaterBijection
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
}
}
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.