ZipInputStream から xml ファイルとその他のコンテンツを抽出し、zipinputstream を解析する xml からオブジェクトを作成しようとしています。ただし、inputStream を読み取る while ループがない場合、次のコードまたは Stream Closed に対して、早すぎるファイル終了例外が発生します。私が理解していることから、 ZipInputStream.getNextEntry は次のエントリの入力ストリームを取得します。
また、実際の一時ファイルを作成して実行し、入力ストリームを渡すと(コメントされたコードのように)、正常に処理されますが、私の場合はディスクに書き込むことができません-したがって、これはすべて-メモリー。mycode のどこが間違っているのか、それを修正するにはどうすればよいか教えてもらえますか?
ZipEntry entry;
Map<String, byte[]> otherElements = new HashMap<String, byte[]>();
entry =((ZipInputStream)inputStream).getNextEntry();
while (entry != null) {
logger.debug("entry: " + entry.getName() + ", " + entry.getSize());
System.out.println(entry.getName() + " - " + entry.getSize());
if (entry.getName().equalsIgnoreCase("Document.xml")) {
/*File file = new File("C:\\tmp.xml");
FileOutputStream fos = new FileOutputStream();
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
fos.write(bytes, 0, read);
}
InputStream fis = new FileInputStream();*/
while(inputStream.available()>0){
inputStream.read();
}
myOutput = buildMyOutput((ZipInputStream)inputStream);
//fos.close();
//fis.close();
// method that takes the input and creates the java object
private MyObject buildMyOutput(InputStream xmlStream) throws Exception {
// build my objects
XStream xstream = ConvertUtil.getXStream();
xstream.processAnnotations(MyObject.class);
MyObject myOutput = (MyObject) xstream.fromXML(xmlStream);
return myOutput;
}