cancel
Showing results for 
Search instead for 
Did you mean: 

updateContent Method automaticaly closes the given InputStream

jochen_wilhelm
Explorer
0 Kudos

Hi,

i want to extract a zip archive within the Repository Framework. I can open and extract/write the first entry, but after that i get an exception which states that the (ZipInput)Stream is already closed.

I suspect the<b> updateContent </b>Method to do that. Is there any way around that autoclosing behavior? Or is there a total different approach to extract archives within the KM?

Many thanks for any hint.

Best regards

Jochen

P.S. i use a Wrapper for the Repository Framework, therefore i didn't yet post any code. But if it helps, i certainly will post it here.

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Jochen,

I don't understand your question completely - you have a ZIP resource and want to extract that, i.e. create several new resources?! In that case, "updateContent" won't be called on the ZIP resource?!

Please give some more details about your scenario, maybe a small portion of the code.

Best regards

Detlev

jochen_wilhelm
Explorer
0 Kudos
ZipInputStream zipIn = new ZipInputStream(zipResource.getContent().getInputStream());
ZipEntry entry = null;
while((entry =zipIn.getNextEntry())!=null)
{
            resource = createResource(entry.getName()); //custom method

           Content content = new Content(zipIn, mimeType, entry.getSize());

           resource.updateContent(content);
}

}

The problem occurs after the first ZipEntry is extracted and written (i also can open the file within the KM UI). But after the first updateContent I than get a "Stream already closed"-Exception!

thank you very much for your help!

best regards

Jochen

P.S. basically i just want to extract a zip resource and create a new resource for each entry.

detlev_beutner
Active Contributor
0 Kudos

Hi Jochen,

I expect the Content constructor to close the passes InputStream.

To circumvent this, I would suggest to "manually" read in the zip input stream into some bytearray and then to create a ByteArrayInputStream and to pass this to the Content constructor. So the RF doesn't have the possibility to touch the ZIP things...

Besides: You are using the Java standard ZIP functionality - this has a bug for many years now, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499 (and the duplicate http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4415733 which has been posted by myself in 2001... oh, how long ago...)

Hope it helps

Detlev

Former Member
0 Kudos

...using byte arrays may not be a good idea when the content is large...

Alternatively, wrap the InputStream object, overwriting the close() method.

Answers (0)