rana_b 2002/10/10 09:04:52
Modified: ftpserver/src/java/org/apache/avalon/ftpserver/util
IoUtils.java
Log:
New util methods added
Revision Changes Path
1.4 +54 -0
jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/IoUtils.java
Index: IoUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/IoUtils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- IoUtils.java 20 May 2002 10:20:18 -0000 1.3
+++ IoUtils.java 10 Oct 2002 16:04:52 -0000 1.4
@@ -1,3 +1,4 @@
+//$Id$
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -39,6 +40,7 @@
return bin;
}
+
/**
* Get a <code>BufferedOutputStream</code>.
*/
@@ -53,6 +55,7 @@
return bout;
}
+
/**
* Get <code>BufferedReader</code>.
*/
@@ -67,6 +70,7 @@
return br;
}
+
/**
* Get <code>BufferedWriter</code>.
*/
@@ -81,6 +85,7 @@
return bw;
}
+
/**
* Get unique file object.
*/
@@ -123,6 +128,7 @@
}
}
+
/**
* No exception <code>java.io.Writer</code> close method.
*/
@@ -132,6 +138,7 @@
}
}
+
/**
* Get exception stack trace.
*/
@@ -150,4 +157,51 @@
}
return result;
}
+
+
+ /**
+ * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
+ * @param bufferSize Size of internal buffer to use.
+ */
+ public static void copy(Reader input, Writer output, int bufferSize ) throws
IOException {
+ char buffer[] = new char[bufferSize];
+ int n = 0;
+ while( (n=input.read(buffer)) != -1) {
+ output.write(buffer, 0, n);
+ }
+ }
+
+ /**
+ * Copy chars from a <code>InputStream</code> to a <code>OutputStream</code>.
+ * @param bufferSize Size of internal buffer to use.
+ */
+ public static void copy(InputStream input, OutputStream output, int bufferSize
) throws IOException {
+ byte buffer[] = new byte[bufferSize];
+ int n = 0;
+ while( (n=input.read(buffer)) != -1) {
+ output.write(buffer, 0, n);
+ }
+ }
+
+
+ /**
+ * Read fully from reader
+ */
+ public static String readFully(Reader reader) throws IOException {
+ StringWriter writer = new StringWriter();
+ copy(reader, writer, 1024);
+ return writer.toString();
+ }
+
+
+ /**
+ * Read fully from stream
+ */
+ public static String readFully(InputStream input) throws IOException {
+ StringWriter writer = new StringWriter();
+ InputStreamReader reader = new InputStreamReader(input);
+ copy(reader, writer, 1024);
+ return writer.toString();
+ }
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>