お世話になっております。
Servletからの他のwebサーバのzipファイルを読み込んで
zip内のファイルを解析したいと考えております。
zipエントリの名前がasciiのみの場合は問題ありませんが、
zipエントリの名前にマルチバイトの文字列が入っていると、
以下のエラーが発生します。
java.lang.IllegalArgumentException
at java.util.zip.ZipInputStream.getUTF8String(Unknown Source)
at java.util.zip.ZipInputStream.getFileName(Unknown Source)
at java.util.zip.ZipInputStream.readLOC(Unknown Source)
at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
・・・
調べたところ、
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4820807
のjavaの問題のようです。
FileOutputStreamを使えれば解決できそうですが、
GAEでは使えないようなので、
何かよい方法はないでしょうか。
以下、テストServletとなります。
-----------------
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class Test extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
URL url = new URL("
http://localhost/test.zip");
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("GET");
http.connect();
InputStream csvin = http.getInputStream();
ZipInputStream zips = new ZipInputStream(csvin);
ZipEntry ze = zips.getNextEntry(); // ここで
java.lang.IllegalArgumentException発生
for (; ze != null; ze = zips.getNextEntry()) {
if (ze.isDirectory()) {
continue;
}
// ファイル操作
}
csvin.close();
zips.close();
http.disconnect();
}
}
-----------------
以上、よろしくお願いします。