This commit is contained in:
wenshao
2012-08-27 16:26:40 +08:00
parent d7e89ae134
commit 19e0cf10f5
5 changed files with 50 additions and 5 deletions
@@ -15,9 +15,11 @@
*/
package com.alibaba.druid.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
@@ -52,6 +54,37 @@ public class IOUtils {
JdbcUtils.close(in);
}
}
public static byte[] readByteArrayFromResource(String resource) throws IOException {
InputStream in = null;
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
if (in == null) {
return null;
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(in, output);
return output.toByteArray();
} finally {
JdbcUtils.close(in);
}
}
public static long copy(InputStream input, OutputStream output)
throws IOException {
final int EOF = -1;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
long count = 0;
int n = 0;
while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
public static String read(Reader reader) {
try {