Commits

Anonymous committed 22de770

Added ProgressListener for monitoring long operations like IOUtils.copy()

  • Participants
  • Parent commits d200f62

Comments (0)

Files changed (2)

ecat-io/src/main/java/org/nrg/IOUtils.java

 	 * Copies all data from in to out
 	 * @param out destination OutputStream
 	 * @param in source InputStream
+	 * @param pl ProgressListener for monitoring the copy
 	 * @throws IOException
 	 */
-	public static void copy(final OutputStream out, final InputStream in)
+	public static void copy(final OutputStream out, final InputStream in, final ProgressListener pl)
 	throws IOException {
 		final byte[] buf = new byte[BUF_SIZE];
 		while (true) {
 				return;
 			} else {
 				out.write(buf, 0, nread);
+				if (null != pl) { pl.incrementProgress(nread); }
 			}
 		}
 	}
+	
+	/**
+	 * Copies all data from in to out
+	 * @param out destination OutputStream
+	 * @param in source InputStream
+	 * @throws IOException
+	 */
+	public static void copy(final OutputStream out, final InputStream in)
+	throws IOException {
+		copy(out, in, null);
+	}
 }

ecat-io/src/main/java/org/nrg/ProgressListener.java

+/**
+ * Copyright (c) 2009 Washington University
+ */
+package org.nrg;
+
+/**
+ * @author Kevin A. Archie <karchie@npg.wustl.edu>
+ *
+ */
+public interface ProgressListener {
+	void setMessage(String message);
+	void incrementProgress(int increment);
+	void incrementTaskSize(int increment);
+}