Java で gzip 圧縮するには java.util.zip.GZIPOutputStream クラスを使う。


import java.io.*;
import java.util.zip.*;
 
public class Gzip {
 
  public static void main(String[] args) throws Exception {
 
    String src = "あいうえお\nかきくけこ";
    FileOutputStream fos = new FileOutputStream("gziptest.gz");
    GZIPOutputStream gos = new GZIPOutputStream(fos);
    byte[] b = src.getBytes("UTF-8");
    for(int i=0; i<b.length; i++){
      gos.write(b[i]);
    }
    gos.close();
 
  }
}

J2ME で gzip 解凍可能なライブラリを発見。これがあれば、携帯電話アプリでも gzip を使える?

TinyLine GZIPInputStream

TinyLine GZIPInputStream is a pure J2ME implementation of the Java 2 java.util.zip.GZIPInputStream class that uses the same API. The size of the class in the JAR format is about 6K. It is developed as a part of TinyLine SVG Toolkit.

TinyLine Downloads

TinyLine GZIPInputStream の使い方サンプル が J2ME.pl : GZIP kompresja danych にある。

Java4Ever Libreria GZIP

Java4Ever - J2ME - Libreria GZIP

Ref. Xyling Java Blog: GZip Library for J2ME

tags: zlashdot Java Java

Posted by NI-Lab. (@nilab)