Clean up single char indexOf()

This commit is contained in:
zzz
2016-12-03 16:00:09 +00:00
parent f461d4881d
commit 42efed578a
16 changed files with 42 additions and 101 deletions

View File

@@ -102,12 +102,7 @@ public class Base32 {
private static byte[] read(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
byte buf[] = new byte[64];
while (true) {
int read = in.read(buf);
if (read < 0) break;
baos.write(buf, 0, read);
}
DataHelper.copy(in, baos);
return baos.toByteArray();
}

View File

@@ -258,12 +258,7 @@ public class Base64 {
private static byte[] read(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
byte buf[] = new byte[1024];
while (true) {
int read = in.read(buf);
if (read < 0) break;
baos.write(buf, 0, read);
}
DataHelper.copy(in, baos);
return baos.toByteArray();
}

View File

@@ -1830,4 +1830,25 @@ public class DataHelper {
}
return p.split(s, limit);
}
/**
* Copy in to out. Caller MUST close the streams.
*
* @param in non-null
* @param out non-null
* @since 0.9.29
*/
public static void copy(InputStream in, OutputStream out) throws IOException {
final ByteCache cache = ByteCache.getInstance(8, 8*1024);
final ByteArray ba = cache.acquire();
try {
final byte buf[] = ba.getData();
int read;
while ((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
}
} finally {
cache.release(ba);
}
}
}