1 19 package org.columba.core.command; 20 21 import java.io.FilterInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 25 import org.columba.api.command.IWorkerStatusController; 26 27 public class ProgressObservedInputStream extends FilterInputStream { 28 29 private IWorkerStatusController status; 30 31 private int read; 32 33 38 public ProgressObservedInputStream(InputStream arg0, 39 IWorkerStatusController theStatusController) { 40 this(arg0, theStatusController, false); 41 } 42 43 48 public ProgressObservedInputStream(InputStream arg0, 49 IWorkerStatusController theStatusController, boolean relative) { 50 super(arg0); 51 this.status = theStatusController; 52 53 if (!relative) { 54 try { 55 theStatusController.setProgressBarMaximum(arg0.available()); 56 } catch (IOException e) { 57 } 59 60 read = 0; 61 } else { 62 read = theStatusController.getProgressBarValue(); 63 } 64 } 65 66 69 @Override 70 public int read() throws IOException { 71 int result = super.read(); 72 if (result != -1) 73 status.setProgressBarValue(++read); 74 return result; 75 } 76 77 80 @Override 81 public int read(byte[] arg0, int arg1, int arg2) throws IOException { 82 int result = super.read(arg0, arg1, arg2); 83 read += result; 84 status.setProgressBarValue(read); 85 86 return result; 87 } 88 } | Popular Tags |