e450. decompressing a byte array.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 26 行

TXT
26
字号
This example decompresses a byte array that was compressed using the Deflater class (see e449 Compressing a Byte Array). 
    // Create the decompressor and give it the data to compress
    Inflater decompressor = new Inflater();
    decompressor.setInput(compressedData);
    
    // Create an expandable byte array to hold the decompressed data
    ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
    
    // Decompress the data
    byte[] buf = new byte[1024];
    while (!decompressor.finished()) {
        try {
            int count = decompressor.inflate(buf);
            bos.write(buf, 0, count);
        } catch (DataFormatException e) {
        }
    }
    try {
        bos.close();
    } catch (IOException e) {
    }
    
    // Get the decompressed data
    byte[] decompressedData = bos.toByteArray();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?