harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r887293 - in /harmony/enhanced/classlib/trunk/modules: archive/src/main/java/java/util/jar/ luni/src/main/java/org/apache/harmony/luni/util/ luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/ rmi/META-INF/ rmi/src/main/java/jav...
Date Fri, 04 Dec 2009 17:44:03 GMT
Author: tellison
Date: Fri Dec  4 17:44:01 2009
New Revision: 887293

URL: http://svn.apache.org/viewvc?rev=887293&view=rev
Log:
Move readFullyAndClose method into LUNI utils' InputStreamHelper, and roll the input stream
exposer code into there too.
Replace a number of places that read the full stream with calls to the new helper.
Part of HARMONY-6393 (fix "new byte[in.available()]" anti-pattern)

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
      - copied, changed from r883721, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
Removed:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
    harmony/enhanced/classlib/trunk/modules/rmi/META-INF/MANIFEST.MF
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
    harmony/enhanced/classlib/trunk/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
Fri Dec  4 17:44:01 2009
@@ -17,19 +17,19 @@
 
 package java.util.jar;
 
-import java.io.ByteArrayOutputStream;
-import java.util.List;
-import java.util.ArrayList;
 import java.io.File;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import org.apache.harmony.archive.internal.nls.Messages;
 import org.apache.harmony.archive.util.Util;
+import org.apache.harmony.luni.util.InputStreamHelper;
 
 /**
  * {@code JarFile} is used to read jar entries and their associated data from
@@ -282,42 +282,6 @@
         return (JarEntry) getEntry(name);
     }
 
-    /*
-     * Drains the entire content from the given input stream and returns it as a
-     * byte[]. The stream is closed after being drained, or if an IOException
-     * occurs.
-     */
-    private byte[] getAllBytesFromStreamAndClose(InputStream is)
-            throws IOException {
-        try {
-            // Initial read
-            byte[] buffer = new byte[1024];
-            int count = is.read(buffer);
-            int nextByte = is.read();
-
-            // Did we get it all in one read?
-            if (nextByte == -1) {
-                byte[] dest = new byte[count];
-                System.arraycopy(buffer, 0, dest, 0, count);
-                return dest;
-            }
-
-            // Requires additional reads
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
-            baos.write(buffer, 0, count);
-            baos.write(nextByte);
-            while (true) {
-                count = is.read(buffer);
-                if (count == -1) {
-                    return baos.toByteArray();
-                }
-                baos.write(buffer, 0, count);
-            }
-        } finally {
-            is.close();
-        }
-    }
-
     /**
      * Returns the {@code Manifest} object associated with this {@code JarFile}
      * or {@code null} if no MANIFEST entry exists.
@@ -340,7 +304,8 @@
         try {
             InputStream is = super.getInputStream(manifestEntry);
             if (verifier != null) {
-                verifier.addMetaEntry(manifestEntry.getName(), getAllBytesFromStreamAndClose(is));
+                verifier.addMetaEntry(manifestEntry.getName(),
+                        InputStreamHelper.readFullyAndClose(is));
                 is = super.getInputStream(manifestEntry);
             }
             try {
@@ -392,7 +357,7 @@
                                 || Util.asciiEndsWithIgnoreCase(entryName, ".RSA"))) {
                     signed = true;
                     InputStream is = super.getInputStream(entry);
-                    byte[] buf = getAllBytesFromStreamAndClose(is);
+                    byte[] buf = InputStreamHelper.readFullyAndClose(is);
                     verifier.addMetaEntry(entryName, buf);
                 }
             }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Manifest.java
Fri Dec  4 17:44:01 2009
@@ -30,7 +30,7 @@
 import java.util.Map;
 
 import org.apache.harmony.archive.internal.nls.Messages;
-import org.apache.harmony.luni.util.InputStreamExposer;
+import org.apache.harmony.luni.util.InputStreamHelper;
 import org.apache.harmony.luni.util.ThreadLocalCache;
 
 /**
@@ -209,7 +209,7 @@
         byte[] buf;
         // Try to read get a reference to the bytes directly
         try {
-            buf = InputStreamExposer.expose(is);
+            buf = InputStreamHelper.expose(is);
         } catch (UnsupportedOperationException uoe) {
             buf = readFully(is);
         }

Copied: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
(from r883721, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java)
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java?p2=harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java&p1=harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java&r1=883721&r2=887293&rev=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
Fri Dec  4 17:44:01 2009
@@ -28,7 +28,7 @@
 /**
  * The class contains static {@link java.io.InputStream} utilities.
  */
-public class InputStreamExposer {
+public class InputStreamHelper {
 
     /**
      * Provides access to a protected underlying buffer of
@@ -47,9 +47,9 @@
         AccessController.doPrivileged(new PrivilegedAction<Object>() {
             public Object run() {
                 try {
-                    f[0] = ByteArrayInputStream.class.getDeclaredField("buf");
+                    f[0] = ByteArrayInputStream.class.getDeclaredField("buf"); //$NON-NLS-1$
                     f[0].setAccessible(true);
-                    f[1] = ByteArrayInputStream.class.getDeclaredField("pos");
+                    f[1] = ByteArrayInputStream.class.getDeclaredField("pos"); //$NON-NLS-1$
                     f[1].setAccessible(true);
                 } catch (NoSuchFieldException nsfe) {
                     throw new InternalError(nsfe.getLocalizedMessage());
@@ -62,6 +62,43 @@
     }
 
     /**
+     * The extension of <code>ByteArrayInputStream</code> which exposes an
+     * underlying buffer.
+     */
+    static class ExposedByteArrayInputStream extends ByteArrayInputStream {
+
+        /**
+         * @see java.io.ByteArrayInputStream(byte[])
+         */
+        public ExposedByteArrayInputStream(byte buf[]) {
+            super(buf);
+        }
+
+        /**
+         * @see java.io.ByteArrayInputStream(byte[], int, int)
+         */
+        public ExposedByteArrayInputStream(byte buf[], int offset, int length) {
+            super(buf, offset, length);
+        }
+
+        /**
+         * Reads the whole stream and returns the stream snapshot.
+         */
+        public synchronized byte[] expose() {
+            if (pos == 0 && count == buf.length) {
+                skip(count);
+                return buf;
+            }
+
+            final int available = available();
+            final byte[] buffer = new byte[available];
+            System.arraycopy(buf, pos, buffer, 0, available);
+            skip(available);
+            return buffer;
+        }
+    }
+
+    /**
      * Reads all bytes from {@link java.io.ByteArrayInputStream} using its
      * underlying buffer directly.
      * 
@@ -99,9 +136,11 @@
      * @param is
      *            the stream to be read.
      * @return the snapshot wrapping the buffer where the bytes are read to.
-     * @throws UnsupportedOperationException if the input stream data cannot be exposed
+     * @throws UnsupportedOperationException
+     *             if the input stream data cannot be exposed
      */
-    public static byte[] expose(InputStream is) throws IOException, UnsupportedOperationException
{
+    public static byte[] expose(InputStream is) throws IOException,
+            UnsupportedOperationException {
         if (is instanceof ExposedByteArrayInputStream) {
             return ((ExposedByteArrayInputStream) is).expose();
         }
@@ -113,4 +152,48 @@
         // We don't know how to do this
         throw new UnsupportedOperationException();
     }
+
+    /**
+     * Reads all the bytes from the given input stream.
+     * 
+     * Calls read multiple times on the given input stream until it receives an
+     * end of file marker. Returns the combined results as a byte array. Note
+     * that this method may block if the underlying stream read blocks.
+     * 
+     * @param is
+     *            the input stream to be read.
+     * @return the content of the stream as a byte array.
+     * @throws IOException
+     *             if a read error occurs.
+     */
+    public static byte[] readFullyAndClose(InputStream is) throws IOException {
+
+        try {
+            // Initial read
+            byte[] buffer = new byte[1024];
+            int count = is.read(buffer);
+            int nextByte = is.read();
+
+            // Did we get it all in one read?
+            if (nextByte == -1) {
+                byte[] dest = new byte[count];
+                System.arraycopy(buffer, 0, dest, 0, count);
+                return dest;
+            }
+
+            // Requires additional reads
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
+            baos.write(buffer, 0, count);
+            baos.write(nextByte);
+            while (true) {
+                count = is.read(buffer);
+                if (count == -1) {
+                    return baos.toByteArray();
+                }
+                baos.write(buffer, 0, count);
+            }
+        } finally {
+            is.close();
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
Fri Dec  4 17:44:01 2009
@@ -58,6 +58,8 @@
 import java.util.TreeSet;
 import java.util.Vector;
 
+import org.apache.harmony.luni.util.InputStreamHelper;
+
 /**
  * Automated Test Suite for class java.io.ObjectOutputStream
  * 
@@ -658,33 +660,25 @@
 		assertTrue("resolved class 3", resolvedClasses[2] == Number.class);
 	}
 
-	public void test_reset() {
-		try {
-			oos.reset();
-			oos.writeObject("R");
-			oos.reset();
-			oos.writeByte(24);
-			oos.close();
-
-			DataInputStream dis = new DataInputStream(loadStream());
-			byte[] input = new byte[dis.available()];
-			dis.readFully(input);
-			byte[] result = new byte[] { (byte) 0xac, (byte) 0xed, (byte) 0,
-					(byte) 5, (byte) 0x79, (byte) 0x74, (byte) 0, (byte) 1,
-					(byte) 'R', (byte) 0x79, (byte) 0x77, (byte) 1, (byte) 24 };
-			assertTrue("incorrect output", Arrays.equals(input, result));
-
-			ois = new ObjectInputStreamSubclass(loadStream());
-			assertEquals("Wrong result from readObject()", "R", ois.readObject()
-					);
-			assertEquals("Wrong result from readByte()", 24, ois.readByte());
-			ois.close();
-		} catch (IOException e1) {
-			fail("IOException : " + e1.getMessage());
-		} catch (ClassNotFoundException e2) {
-			fail("ClassNotFoundException : " + e2.getMessage());
-		}
-	}
+    public void test_reset() throws IOException, ClassNotFoundException {
+        oos.reset();
+        oos.writeObject("R");
+        oos.reset();
+        oos.writeByte(24);
+        oos.close();
+
+        DataInputStream dis = new DataInputStream(loadStream());
+        byte[] input = InputStreamHelper.readFullyAndClose(dis);
+        byte[] result = new byte[] { (byte) 0xac, (byte) 0xed, (byte) 0,
+                (byte) 5, (byte) 0x79, (byte) 0x74, (byte) 0, (byte) 1,
+                (byte) 'R', (byte) 0x79, (byte) 0x77, (byte) 1, (byte) 24 };
+        assertTrue("incorrect output", Arrays.equals(input, result));
+
+        ois = new ObjectInputStreamSubclass(loadStream());
+        assertEquals("Wrong result from readObject()", "R", ois.readObject());
+        assertEquals("Wrong result from readByte()", 24, ois.readByte());
+        ois.close();
+    }
 
 	public void test_serialVersionUID(Class clazz, long svUID) throws Exception {
 		final String idWrong = "serialVersionUID is wrong for: ";

Modified: harmony/enhanced/classlib/trunk/modules/rmi/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/META-INF/MANIFEST.MF?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/META-INF/MANIFEST.MF Fri Dec  4 17:44:01 2009
@@ -23,6 +23,7 @@
  javax.net,
  javax.net.ssl,
  org.apache.harmony.kernel.vm,
+ org.apache.harmony.luni.util,
  org.apache.harmony.testframework.serialization;hy_usage=test;resolution:=optional
 Export-Package: java.rmi,
  java.rmi.activation,

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
Fri Dec  4 17:44:01 2009
@@ -29,6 +29,7 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
+import org.apache.harmony.luni.util.InputStreamHelper;
 import org.apache.harmony.rmi.DefaultRMIClassLoaderSpi;
 import org.apache.harmony.rmi.internal.nls.Messages;
 
@@ -210,9 +211,7 @@
             // resource not found
             return null;
         }
-        Object obj = null;
-        byte[] buf = new byte[in.available()];
-        in.read(buf);
+        byte[] buf = InputStreamHelper.readFullyAndClose(in);
         String str = new String(buf, "UTF-8"); //$NON-NLS-1$
         StringTokenizer tok = new StringTokenizer(str, "\n\r"); //$NON-NLS-1$
 

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
Fri Dec  4 17:44:01 2009
@@ -38,6 +38,7 @@
 
 import javax.security.auth.x500.X500Principal;
 
+import org.apache.harmony.luni.util.InputStreamHelper;
 import org.apache.harmony.security.asn1.BerInputStream;
 import org.apache.harmony.security.internal.nls.Messages;
 import org.apache.harmony.security.pkcs7.ContentInfo;
@@ -144,8 +145,7 @@
         // Otherwise, compute the message digest on the data.
         List atr = sigInfo.getAuthenticatedAttributes();
 
-        byte[] sfBytes = new byte[signature.available()];
-        signature.read(sfBytes);
+        byte[] sfBytes = InputStreamHelper.readFullyAndClose(signature);
 
         if (atr == null) {
             sig.update(sfBytes);    

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
Fri Dec  4 17:44:01 2009
@@ -17,7 +17,6 @@
 
 package org.apache.harmony.security.tests.java.security;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -29,6 +28,8 @@
 import java.util.Enumeration;
 import java.util.jar.JarFile;
 
+import org.apache.harmony.luni.util.InputStreamHelper;
+
 import tests.support.Support_GetLocal;
 
 public class SecureClassLoader2Test extends junit.framework.TestCase {
@@ -61,47 +62,11 @@
 
         File file = Support_GetLocal.getLocalFile("hyts_security.jar");
         JarFile jar = new JarFile(file);
-        InputStream in = jar.getInputStream(jar
-                .getEntry("packA/SecurityTest.class"));
-        byte[] bytes = drain(in);
+        InputStream in = jar.getInputStream(jar.getEntry("packA/SecurityTest.class"));
+        byte[] bytes = InputStreamHelper.readFullyAndClose(in);
         Class c = myloader.define("packA.SecurityTest", bytes);
 		ProtectionDomain pd = c.getProtectionDomain();
 		assertNotNull("Expected dynamic policy", pd.getClassLoader());
 		assertNull("Expected null permissions", pd.getPermissions());
 	}
-
-    /*
-     * Drains the entire content from the given input stream and returns it as a
-     * byte[]. The stream is closed after being drained, or if an IOException
-     * occurs.
-     */
-    private byte[] drain(InputStream is) throws IOException {
-        try {
-            // Initial read
-            byte[] buffer = new byte[1024];
-            int count = is.read(buffer);
-            int nextByte = is.read();
-
-            // Did we get it all in one read?
-            if (nextByte == -1) {
-                byte[] dest = new byte[count];
-                System.arraycopy(buffer, 0, dest, 0, count);
-                return dest;
-            }
-
-            // Requires additional reads
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
-            baos.write(buffer, 0, count);
-            baos.write(nextByte);
-            while (true) {
-                count = is.read(buffer);
-                if (count == -1) {
-                    return baos.toByteArray();
-                }
-                baos.write(buffer, 0, count);
-            }
-        } finally {
-            is.close();
-        }
-    }
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java?rev=887293&r1=887292&r2=887293&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java
Fri Dec  4 17:44:01 2009
@@ -17,12 +17,11 @@
 
 package org.apache.harmony.sound.utils;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.InputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -31,6 +30,8 @@
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.harmony.luni.util.InputStreamHelper;
+
 public class ProviderService {
 
     // Properties from sound.propertie file
@@ -145,7 +146,7 @@
                             try {
                                 InputStream in = urls.nextElement()
                                         .openStream();
-                                bytes = getAllBytesFromStreamAndClose(in);
+                                bytes = InputStreamHelper.readFullyAndClose(in);
                             } catch (IOException e) {
                                 continue;
                             }
@@ -172,41 +173,5 @@
     public static Properties getSoundProperties() {
         return devices;
     }
-    
-    /*
-     * Drains the entire content from the given input stream and returns it as a
-     * byte[]. The stream is closed after being drained, or if an IOException
-     * occurs.
-     */
-    private static byte[] getAllBytesFromStreamAndClose(InputStream is)
-            throws IOException {
-        try {
-            // Initial read
-            byte[] buffer = new byte[512];
-            int count = is.read(buffer);
-            int nextByte = is.read();
-
-            // Did we get it all in one read?
-            if (nextByte == -1) {
-                byte[] dest = new byte[count];
-                System.arraycopy(buffer, 0, dest, 0, count);
-                return dest;
-            }
-
-            // Requires additional reads
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
-            baos.write(buffer, 0, count);
-            baos.write(nextByte);
-            while (true) {
-                count = is.read(buffer);
-                if (count == -1) {
-                    return baos.toByteArray();
-                }
-                baos.write(buffer, 0, count);
-            }
-        } finally {
-            is.close();
-        }
-    }
 
 }



Mime
View raw message