Jan 06, 2006
jLHA にチャレンジ
jLHA とは
jLHA は、名前の通り Java で LHA を扱うためのライブラリ。 J2SE にある ZIP 用 API と似通ったインターフェースを持っているため使いやすい。 ライセンスは独自ライセンスになっている。
- LHA Library for Java
- http://homepage1.nifty.com/dangan/Content/Program/Java/jLHA/LhaLibrary.html
jLHA の実行環境構築
- こちらから jLHA のソースコードをダウンロードする(ここでは version 0.06-05 を使用)。
- compile.xml 内の javac.target のvalue="1.1"をvalue="1.5"に変更する。
- jLHA をコンパイルして jar を生成する。ここでは、JDK 1.5.0_05 と Ant 1.6.2 を使用した。
> ant -f compile.xml compileRelease > jar cvf jlha-0.06-05.jar jp
- jlha-0.06-05.jar をクラスパスに指定する。
サンプルコード
package jp.in_vitro.codelets.jlha;
import java.io.IOException;
import java.io.InputStream;
import jp.gr.java_conf.dangan.util.lha.LhaFile;
import jp.gr.java_conf.dangan.util.lha.LhaHeader;
public class Codelet {
public Codelet() {
super();
}
public static void main(String[] args) throws IOException {
Codelet me = new Codelet();
me.execute();
}
protected void execute() throws IOException {
LhaFile file = new LhaFile("c:\\sample.lzh");
LhaHeader[] entries = file.getEntries();
String path = null;
for (LhaHeader entry : entries) {
path = entry.getPath();
System.out.println("" + path);
InputStream is = null;
try {
is = file.getInputStream(path);
int ch = 0;
while ((ch = is.read()) >= 0) {
System.out.print((char) ch);
}
System.out.println();
} finally {
if (is != null) {
is.close();
}
}
}
}
}
TrackBack ping me at
http://www.in-vitro.jp/blog/index.cgi/Library/20060106_01.trackback
writeback message: Ready to post a comment.
