dlr 01/08/15 15:57:03
Modified: util/src/java/org/apache/commons/util StreamUtils.java
Log:
The trimBuffer() class method turned out to not be all that necessary.
Revision Changes Path
1.2 +5 -26
jakarta-commons-sandbox/util/src/java/org/apache/commons/util/StreamUtils.java
Index: StreamUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/util/src/java/org/apache/commons/util/StreamUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -u -r1.1 -r1.2
--- StreamUtils.java 2001/08/15 22:18:36 1.1
+++ StreamUtils.java 2001/08/15 22:57:03 1.2
@@ -66,7 +66,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leonard Richardson</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
- * @version $Id: StreamUtils.java,v 1.1 2001/08/15 22:18:36 leonardr Exp $
+ * @version $Id: StreamUtils.java,v 1.2 2001/08/15 22:57:03 dlr Exp $
*/
public class StreamUtils
{
@@ -104,15 +104,13 @@
String encoding)
throws IOException
{
- int bytesRead;
- byte[] buffer = new byte[bufferSize];
- byte[] newBuffer;
ByteArrayOutputStream contents = new ByteArrayOutputStream();
+ byte[] buffer = new byte[bufferSize];
+ int bytesRead;
while ( (bytesRead = toRead.read(buffer)) != -1 )
{
- newBuffer = trimBuffer(buffer, bytesRead);
- contents.write(newBuffer, 0, newBuffer.length);
+ contents.write(buffer, 0, bytesRead);
}
return (encoding == null ? contents.toString() :
@@ -149,27 +147,8 @@
int bytesRead;
while ( (bytesRead = toRead.read(buffer)) != -1 )
- {
- toWrite.write(trimBuffer(buffer, bytesRead));
- }
- }
-
- /**
- * If a buffer was not filled up by a read, this method will swap
- * it for a new buffer of the appropriate size.
- *
- * @param buffer The buffer to trim.
- * @param size The size to trim the buffer to.
- * @return A trimmed version of the buffer.
- */
- private static byte[] trimBuffer(byte[] buffer, int size)
- {
- byte[] newBuffer = buffer;
- if (size < buffer.length)
{
- newBuffer = new byte[size];
- System.arraycopy(buffer, 0, newBuffer, 0, size);
+ toWrite.write(buffer, 0, bytesRead);
}
- return newBuffer;
}
}