[jboss-cvs] JBossAS SVN: r91857 - projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 30 21:41:28 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-07-30 21:41:27 -0400 (Thu, 30 Jul 2009)
New Revision: 91857
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java
Log:
Minor cleanup
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java 2009-07-31 01:34:35 UTC (rev 91856)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java 2009-07-31 01:41:27 UTC (rev 91857)
@@ -28,7 +28,6 @@
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.ByteArrayInputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -69,6 +68,9 @@
/** Standard separator for JAR URL */
public static final String JAR_URL_SEPARATOR = "!/";
+ /** The default buffer size to use for copies */
+ public static final int DEFAULT_BUFFER_SIZE = 65536;
+
private VFSUtils()
{
}
@@ -366,12 +368,30 @@
*/
public static void copyStreamAndClose(InputStream is, OutputStream os) throws IOException
{
+ copyStreamAndClose(is, os, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Copy input stream to output stream and close them both
+ *
+ * @param is input stream
+ * @param os output stream
+ * @param bufferSize the buffer size to use
+ * @throws IOException for any error
+ */
+ public static void copyStreamAndClose(InputStream is, OutputStream os, int bufferSize)
+ throws IOException
+ {
try
{
- copyStream(is, os);
+ copyStream(is, os, bufferSize);
+ // throw an exception if the close fails since some data might be lost
+ is.close();
+ os.close();
}
finally
{
+ // ...but still guarantee that they're both closed
safeClose(is);
safeClose(os);
}
@@ -387,18 +407,28 @@
*/
public static void copyStream(InputStream is, OutputStream os) throws IOException
{
+ copyStream(is, os, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Copy input stream to output stream without closing streams.
+ * Flushes output stream when done.
+ *
+ * @param is input stream
+ * @param os output stream
+ * @param bufferSize the buffer size to use
+ * @throws IOException for any error
+ */
+ public static void copyStream(InputStream is, OutputStream os, int bufferSize)
+ throws IOException
+ {
if (is == null)
throw new IllegalArgumentException("input stream is null");
if (os == null)
throw new IllegalArgumentException("output stream is null");
-
- byte [] buff = new byte[65536];
- int rc = is.read(buff);
- while (rc != -1)
- {
- os.write(buff, 0, rc);
- rc = is.read(buff);
- }
+ byte [] buff = new byte[bufferSize];
+ int rc;
+ while ((rc = is.read(buff)) != -1) os.write(buff, 0, rc);
os.flush();
}
More information about the jboss-cvs-commits
mailing list