Package org.toubassi.femtozip.substring

Examples of org.toubassi.femtozip.substring.SubstringUnpacker


        getSubstringPacker().pack(data, this, new PrintWriter(out));
    }

    public byte[] decompress(byte[] compressedData) {
        try {
            SubstringUnpacker unpacker = new SubstringUnpacker(dictionary);
            String source = new String(compressedData, "UTF-8");
            for (int i = 0, count = source.length(); i < count; i++) {
                char ch = source.charAt(i);
                if (ch == '<') {
                    int rightAngleIndex = source.indexOf('>', i);
                    String substring = source.substring(i + 1, rightAngleIndex);
                    String[] parts = substring.split(",");
                    int offset = Integer.parseInt(parts[0]);
                    int length = Integer.parseInt(parts[1]);
                   
                    unpacker.encodeSubstring(offset, length, null);
                    // Skip past this in the outer loop
                    i = rightAngleIndex;
                }
                else {
                    unpacker.encodeLiteral((int)ch, null);
                }
            }
            unpacker.endEncoding(null);
            return unpacker.getUnpackedBytes();
        }
        catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here


   
    public byte[] decompress(byte[] compressedBytes) {
        try {
            ByteArrayInputStream bytesIn = new ByteArrayInputStream(compressedBytes);
            HuffmanDecoder decoder = new HuffmanDecoder(codeModel.createModel(), bytesIn);
            SubstringUnpacker unpacker = new SubstringUnpacker(dictionary);
       
            int nextSymbol;
            while ((nextSymbol = decoder.decodeSymbol()) != -1) {
                if (nextSymbol > 255) {
                    int length = nextSymbol - 256;
                    int offset = decoder.decodeSymbol() | (decoder.decodeSymbol() << 4) | (decoder.decodeSymbol() << 8) | (decoder.decodeSymbol() << 12);
                    offset = -offset;
                    unpacker.encodeSubstring(offset, length, null);
                }
                else {
                    unpacker.encodeLiteral(nextSymbol, null);
                }
            }
            unpacker.endEncoding(null);
            return unpacker.getUnpackedBytes();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }   
View Full Code Here

TOP

Related Classes of org.toubassi.femtozip.substring.SubstringUnpacker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.