Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright (c) 2011 Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany.
   *  All rights reserved. This program and the accompanying materials
   *  are made available under the terms of the GNU Lesser Public License v2.1
   *  which accompanies this distribution, and is available at
   *  http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
   *
   *  Contributors:
   *      Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany - RMI Client, FileChooser and WebDAV
  */
 package de.ipk_gatersleben.bit.bi.edal.publication.metadata;
 
 
 public class FileProgressInputStream extends FilterInputStream {
 
 	private int nread = 0;
 	private int size = 0;
 	private long steps = 0;

Constructs an object to monitor the progress of an input stream.

Parameters:
inputStream The input stream to be monitored.
 
 	public FileProgressInputStream(JProgressBar fileProgressBar,
 			InputStream inputStream) {
 		super(inputStream);
 		this. = fileProgressBar;
 		try {
 			 = inputStream.available();
 		} catch (IOException ioe) {
 			 = 0;
 		}
 
 	}

Get the ProgressMonitor object being used by this stream. Normally this isn't needed unless you want to do something like change the descriptive text partway through reading the file.

Returns:
the ProgressMonitor object used by this object
 
 		return this.;
 	}

Overrides FilterInputStream.read to update the progress monitor after the read.
 
 	public int read() throws IOException {
 		int c = .read();
 		if (c >= 0)
 
 		return c;
 	}

Overrides FilterInputStream.read to update the progress monitor after the read.
 
 	public int read(byte b[]) throws IOException {
 		int nr = .read(b);
 		if (nr > 0)
 			this..setProgress( += nr);
 		return nr;
 	}

Overrides FilterInputStream.read to update the progress monitor after the read.
 
 	public int read(byte b[], int offint lenthrows IOException {
 
 		// if (nread < 100000) {
 		// System.out.println("IN: " + in.available() + "\t NV: " + nread);
 		// }
 
 		String prepareCopy = "Prepare Copying : ";
 
 		if (.available() == ) {
 
 			String label = this..getString();
 			if (label.indexOf(prepareCopy) == -1) {
 				this..setString(prepareCopy + label);
 			}
 
 			.setProgress((int) ( * 100));
 
else {
			String label = this..getString();
			if (label.indexOf(prepareCopy) != -1) {
						label.indexOf(prepareCopy) + prepareCopy.length(),
						label.length()));
			}
		}
		int nr = .read(bofflen);
		// if (nr > 0) {
		// monitor.setProgress(nread += nr);
		// }
		return nr;
	}

Overrides FilterInputStream.skip to update the progress monitor after the skip.
	public long skip(long nthrows IOException {
		long nr = .skip(n);
		if (nr > 0)
		return nr;
	}

Overrides FilterInputStream.close to close the progress monitor as well as the stream.
	public void close() throws IOException {
	}

Overrides FilterInputStream.reset to reset the progress monitor as well as the stream.
	public synchronized void reset() throws IOException {
	}
New to GrepCode? Check out our FAQ X