Java Decompress Byte Array decompress(final DataInputStream input, final byte[] result, int offset, int length)

Here you can find the source of decompress(final DataInputStream input, final byte[] result, int offset, int length)

Description

decompress

License

Open Source License

Declaration

static void decompress(final DataInputStream input,
            final byte[] result, int offset, int length) throws IOException 

Method Source Code

//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;
        }
    }
}

Related

  1. decompress(byte[] source)
  2. decompress(byte[] src, Inflater decompresser, int compressCycleSize)
  3. decompress(byte[] str)
  4. decompress(byte[] zipByte)
  5. decompress(final byte[] compressed)
  6. decompressAndB64DecodeUTF8Bytes(byte[] b64EncodedCompressedBytes)
  7. decompressByte(byte[] decompress)
  8. decompressByteArray(byte[] compressedData)
  9. decompressBytes(byte bytess[][])