Use copyStream to read file
(Also, increase bufferSize to the value readStream() has used before)
This commit is contained in:
parent
80f7d0e601
commit
db605bcd5c
@ -56,7 +56,7 @@ public class IITC_FileManager {
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// in case Android includes Apache commons IO in the future, this function should be replaced by IOUtils.copy
|
// 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];
|
final byte[] buffer = new byte[bufferSize];
|
||||||
int len = 0;
|
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<String, String> getScriptInfo(final String js) {
|
public static HashMap<String, String> getScriptInfo(final String js) {
|
||||||
final HashMap<String, String> map = new HashMap<String, String>();
|
final HashMap<String, String> map = new HashMap<String, String>();
|
||||||
String header = "";
|
String header = "";
|
||||||
@ -123,6 +105,18 @@ public class IITC_FileManager {
|
|||||||
return map;
|
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 AssetManager mAssetManager;
|
||||||
private final IITC_Mobile mIitc;
|
private final IITC_Mobile mIitc;
|
||||||
private final String mIitcPath;
|
private final String mIitcPath;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user