harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessewil...@apache.org
Subject svn commit: r834316 - /harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Streams.java
Date Tue, 10 Nov 2009 03:06:30 GMT
Author: jessewilson
Date: Tue Nov 10 03:06:30 2009
New Revision: 834316

URL: http://svn.apache.org/viewvc?rev=834316&view=rev
Log:
A helper class for writing I/O tests. I couldn't find a location for general purpose test
utilities like this one, so I created a new one.

Added:
    harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Streams.java

Added: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Streams.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Streams.java?rev=834316&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Streams.java (added)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Streams.java Tue Nov
10 03:06:30 2009
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package tests.support;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Utility methods for working with byte and character streams.
+ */
+public class Streams {
+
+    /**
+     * Drains the stream into a byte array and returns the result.
+     */
+    public static byte[] bytesFromStream(InputStream source) throws IOException {
+        byte[] buffer = new byte[1024];
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int count;
+        while ((count = source.read(buffer)) != -1) {
+            out.write(buffer, 0, count);
+        }
+        return out.toByteArray();
+    }
+}



Mime
View raw message