As far as what the problem is, I'm not exactly sure. However, the following code should be revealing. See what it it tells you:
val buff = new Array[Byte](1024)
var len = 0
while((len = bin.read(buff)) != -1) {
//Print out actual contents of buff:
for(int i = 0; i < buff.length; i++) {
System.out.print(i + "=" + buff[i] + ", ");
}
System.out.println();
gzip.write(buff, 0, len) // java.lang.IndexOutOfBoundsException is thrown!
}
This is just my style-opinion, but I personally find this confusing
while((len = bin.read(buff)) != -1) {
and would change it to
len = bin.read(buff);
while(len != -1) {
//do stuff
len = bin.read(buff);
}