I am attempting to read in a stream and save the read images to a zip file as this is going to be running over multiple days and would generate far too many individual files.
I now have an issue where I seem to be unable to save images into a zip file. The worker thread I have built for it is below. I am sure that the image is making it to the ImageIO.write. The result at the end however is a zip file of empty jpgs. I am wondering if perhaps ImageIO is not writing property to the ZipOutputStream.
Thanks for your help.
public class ZipSaveWorker implements Runnable{
public static ZipOutputStream out=null;
BufferedImage myImage;
private static int counter=0;
public void run() {
ZipEntry entry=new ZipEntry("video"+counter+".jpg");
counter++;
try {
out.putNextEntry(entry);
ImageIO.write(myImage, ".jpg", out);
} catch (IOException ex) {
Logger.getLogger(ZipSaveWorker.class.getName()).log(Level.SEVERE, null, ex);
}
}
public ZipSaveWorker(BufferedImage image)
{
if (out==null)
{
try {
out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(new File("images" + File.separator + "video.zip"))));
} catch (FileNotFoundException ex) {
Logger.getLogger(ZipSaveWorker.class.getName()).log(Level.SEVERE, null, ex);
}
counter=0;
}
myImage=image;
}
public static void closeStream()
{
try {
out.flush();
out.close();
} catch (IOException ex) {
Logger.getLogger(ZipSaveWorker.class.getName()).log(Level.SEVERE, null, ex);
}
}
}