* @throws IOException
*/
private void writeObject(ObjectOutputStream out)
throws IOException
{
PutField fields = out.putFields();
byte[] zisBytes = null;
ZipInputStream jarStream = zis;
if(jarStream == null)
{
// Need to obtain this nested jar input stream from parent
InputStream parentIS = super.getParent().openStream();
if(parentIS == null)
throw new IOException("Failed to open parent stream, "+this);
if(parentIS instanceof ZipInputStream)
{
jarStream = (ZipInputStream) parentIS;
}
else
{
jarStream = new ZipInputStream(parentIS);
}
// First find our entry
ZipEntry entry = jarStream.getNextEntry();
while(entry != null)
{
if(entry.getName().equals(getName()))
break;
entry = jarStream.getNextEntry();
}
if(entry == null)
throw new IOException("Failed to find nested jar entry: "+this.getName()+" in parent: "+getParent());
}
// Now read zis for this entry
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] tmp = new byte[1024];
int length = jarStream.read(tmp);
while(length > 0)
{
baos.write(tmp, 0, length);
length = jarStream.read(tmp);
}
jarStream.close();
jarStream = null;
zisBytes = baos.toByteArray();
fields.put("zisBytes", zisBytes);
fields.put("jarURL", jarURL);
fields.put("entryURL", entryURL);
fields.put("lastModified", lastModified);
fields.put("size", size);
out.writeFields();
}