Link to home
Start Free TrialLog in
Avatar of csound
csound

asked on

ProgressMonitorInputStream

Can anyone please tell me how to assign ProgressMonitorInputStream to the following code? So that we can see how far the process has completed.
     
ArrayList images=new ArrayList();

     ZipInputStream zin = new ZipInputStream(new FileInputStream(filename));
     ZipEntry zent=     zin.getNextEntry();
     JPEGImageDecoder decoder1=JPEGCodec.createJPEGDecoder(zin);
     BufferedImage bi1=decoder1.decodeAsBufferedImage();
     AffineTransformOp aop1=new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_BILINEAR);
     BufferedImageFilter bif1=new BufferedImageFilter(aop1);
     FilteredImageSource fsource1=new FilteredImageSource(bi1.getSource(), bif1);
     Image img1=Toolkit.getDefaultToolkit().createImage(fsource1);



     images.add(new ImageIcon(img1, "Map"));
     zin.closeEntry();
     zent=zin.getNextEntry();

     while(! zent .getName().equals("data.ser"))
         {
          JPEGImageDecoder decoder2=JPEGCodec.createJPEGDecoder(zin);
          BufferedImage bi2=decoder2.decodeAsBufferedImage();
          AffineTransformOp aop2=new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_BILINEAR);
          BufferedImageFilter bif2=new BufferedImageFilter(aop2);
          FilteredImageSource fsource2=new FilteredImageSource(bi2.getSource(), bif2);
          Image img2=Toolkit.getDefaultToolkit().createImage(fsource2);
          String imgName=new File(zent.getName()).getName();
          images.add(new ImageIcon(img2, imgName.endsWith(".jpg")?imgName.substring(0,imgName.length()-4):imgName));
          zent=zin.getNextEntry();
         }

     ObjectInputStream oin = new ObjectInputStream(zin);

     Object data= oin.readObject();

     zin.closeEntry();
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

It would be more appropriate IMHO to use a progress monitor on zip entries rather than use ProgressMonitorInputStream
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ZipInputStream zin = new ZipInputStream(
   new ProgressMonitorInputStream(comp, "Unzipping...",
new FileInputStream(filename)));
   
Avatar of csound
csound

ASKER

-> CEHJ
what's IMHO?
in my humble opinion. But give it a try with objects' suggestion first.
Avatar of csound

ASKER

The progress monitor does not get displayed..
It may not need to, it only displays if the reading takes a while.
How big is your zip file?

http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

Avatar of csound

ASKER

The progress monitor does not get displayed..
You can adjust the settings using the ProgressMonitor class.
Avatar of csound

ASKER

The file size was about 70K.
Avatar of csound

ASKER

So I have to
ProgressMonitorInputStream pmi=new ProgressMonitorInputStream(comp, "Unzipping...",
new FileInputStream(filename));

ProgressMonitor pm=pmi.getProgressMonitor();
//do some setting

ZipInputStream zin = new ZipInputStream(
pmi);

Is this correct?
It seems to me the processing overhead is confined to what's going on in your loop, which is a good reason why the progress monitor should not be attached to the input stream
csound> Is this correct?

yes

cehj> It seems to me the processing overhead is confined to
cehj> what's going on in your loop, which is a good reason why
cehj> the progress monitor should not be attached to the input stream

But the loop is reading the stream?

I suppose if the next read of the stream is going to have to wait on the processing, then it can be made to amount to the same thing yes.