正直なところ、これにはそれほど多くの問題があるべきではありませんが、明らかな何かが欠けているに違いありません。
を使用してファイルをうまく圧縮できますGZIPOutputStream
が、入力を直接(ファイルからではなく、パイプなどから)取得しようとすると、ファイルでgunzip -d を呼び出して正しく解凍されるかどうかを確認すると、すぐにファイルの終わりに達したことを教えてくれます。基本的に、これらを機能させたい
echo foo | java Jgzip >foo.gz
また
java Jzip <test.txt >test.gz
そして、これらが文字列であるという保証はないので、バイト単位で読み取ります。を使えばいいと思っSystem.in and System.out
たのですが、うまくいかないようです。
public static void main (String[] args) {
try{
BufferedInputStream bf = new BufferedInputStream(System.in);
byte[] buff = new byte[1024];
int bytesRead = 0;
GZIPOutputStream gout = new GZIPOutputStream (System.out);
while ((bytesRead = bf.read(buff)) != -1) {
gout.write(buff,0,bytesRead);
}
}
catch (IOException ioe) {
System.out.println("IO error.");
System.exit(-1);
}
catch (Throwable e) {
System.out.println("Unexpected exception or error.");
System.exit(-1);
}
}