Here you can find the source of decompress(final DataInputStream input, final byte[] result, int offset, int length)
static void decompress(final DataInputStream input, final byte[] result, int offset, int length) throws IOException
//package com.java2s; import java.io.DataInputStream; import java.io.IOException; public class Main { static void decompress(final DataInputStream input, final byte[] result, int offset, int length) throws IOException { int resultPos = offset; int remaining = length; while (remaining > 0) { byte run = input.readByte(); int runLength; if ((run & 0x80) != 0) { // Compressed run runLength = run + 131; // PackBits: -run + 1 and run == 0x80 is no-op... This allows 1 byte longer runs... byte runData = input.readByte(); for (int i = 0; i < runLength; i++) { result[resultPos++] = runData; }//from w ww . j a v a 2 s .c o m } else { // Uncompressed run runLength = run + 1; input.readFully(result, resultPos, runLength); resultPos += runLength; } remaining -= runLength; } } }