From db605bcd5c48fa067c54d73a9984399c8ae99f44 Mon Sep 17 00:00:00 2001 From: fkloft Date: Wed, 22 Jan 2014 19:24:41 +0100 Subject: [PATCH] Use copyStream to read file (Also, increase bufferSize to the value readStream() has used before) --- .../cradle/iitc_mobile/IITC_FileManager.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_FileManager.java b/mobile/src/com/cradle/iitc_mobile/IITC_FileManager.java index 6fe49f1c..6ec999eb 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_FileManager.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_FileManager.java @@ -56,7 +56,7 @@ public class IITC_FileManager { throws IOException { // in case Android includes Apache commons IO in the future, this function should be replaced by IOUtils.copy - final int bufferSize = 1024; + final int bufferSize = 4096; final byte[] buffer = new byte[bufferSize]; int len = 0; @@ -70,24 +70,6 @@ public class IITC_FileManager { } } - public static String readStream(final InputStream stream) { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final byte[] buffer = new byte[4096]; - - try { - while (true) { - final int read = stream.read(buffer); - if (read == -1) - break; - os.write(buffer, 0, read); - } - } catch (final IOException e) { - Log.w(e); - return ""; - } - return os.toString(); - } - public static HashMap getScriptInfo(final String js) { final HashMap map = new HashMap(); String header = ""; @@ -123,6 +105,18 @@ public class IITC_FileManager { return map; } + public static String readStream(final InputStream stream) { + final ByteArrayOutputStream os = new ByteArrayOutputStream(); + + try { + copyStream(stream, os, true); + } catch (final IOException e) { + Log.w(e); + return ""; + } + return os.toString(); + } + private final AssetManager mAssetManager; private final IITC_Mobile mIitc; private final String mIitcPath;