I'm trying to create zip files using java.util.zip in Avian, and am having two problems.
The first is that the written to disk by the zip.output stream is the same size as when written to disk using file output stream.
The second is when calling zipOutputStream.closeEntry(); I receive the following error from the program:
I would also note that I've tried using java.util.Deflater and Inflater on the byte array, and they appear to work correctly. Here is the code I'm using:
private void saveAsCompressedBitmap(byte[] bytes, String fn)
{
String zFn = fn + ".zip";
fn += ".bmp";
// Avian doesn't support try-with-resources and FileOutputStream, ZipOutputStream
FileOutputStream fos = null;
ZipOutputStream zos = null;
try //(FileOutputStream fos = new FileOutputStream(FPATH + zFn);
//ZipOutputStream zos = new ZipOutputStream(fos);)
{
fos = new FileOutputStream(FPATH + zFn);
zos = new ZipOutputStream(fos);
ZipEntry ze = new ZipEntry(fn);
zos.putNextEntry(ze);
zos.write(bytes);
}
catch(IOException ie)
{
System.out.println("saveAsCompressedBitmap failed!");
for (StackTraceElement ste : ie.getStackTrace())
System.err.println(ste.toString());
}
finally
{
try
{
if (zos != null)
{
zos.closeEntry(); // This is where the exception is being generated.
zos.close();
}
if (fos != null) fos.close();
}
catch(Exception e)
{
// TODO Auto-generated catch block
for (StackTraceElement ste : e.getStackTrace())
System.err.println(ste.toString());
}
}
}