main.java

来自「java的经典例子」· Java 代码 · 共 37 行

JAVA
37
字号
import java.io.*;
import java.util.zip.*;

class Main {
    public static void main(String[] args) {
        try {
            MyGZIPInputStream is = new MyGZIPInputStream(System.in);
            byte[] buf = new byte[1024];
            int len;

            while (!is.getEos()) {
                len = is.read(buf);
                if (len > 0) {
                    System.out.write(buf, 0, len);
                }
            }
            is.close();
            System.err.println("\nThe checksum is: " + 
                               is.getChecksum().getValue());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyGZIPInputStream extends GZIPInputStream {
    MyGZIPInputStream(InputStream in) throws IOException {
        super(in);
    }
    boolean getEos() {
        return eos;
    }
    Checksum getChecksum() {
        return crc;
    }
}

⌨️ 快捷键说明

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