summaryrefslogtreecommitdiffstats
blob: 2c78a571bfe727ee5b5b32a6eefc2b6cc7836717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright (c) 2011, Isode Limited, London, England.
 * All rights reserved.
 */
package com.isode.stroke.compress;

import com.isode.stroke.base.ByteArray;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

/**
 *
 * @author Kev
 */
public class ZLibDecompressor {
    Inflater inflater_ = new Inflater();
    public ByteArray process(ByteArray data) throws ZLibException {
        try {
            inflater_.setInput(data.getData());
            byte[] output = new byte[100];
            ByteArray result = new ByteArray();
            int size = 0;
            while ((size = inflater_.inflate(output)) != 0) {
                for (int i = 0; i < size; i++) {
                    result.append(output[i]); /* TODO: Terribly slow */
                }
            }
            return result;
        }
        catch (DataFormatException e) {
            throw new ZLibException();
        }
    }

}