1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.portletbridge.portlet;
17
18 import java.io.BufferedOutputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23
24 /***
25 * @author jmccrindle
26 */
27 public class ResourceUtil {
28
29 private ResourceUtil() {
30 super();
31 }
32
33 public static void copy(InputStream inputStream, OutputStream outputStream,
34 int bufSize) throws IOException {
35 InputStream in = inputStream;
36 BufferedOutputStream out = new BufferedOutputStream(outputStream,
37 bufSize);
38 try {
39 byte[] b = new byte[4096];
40 int i = -1;
41 while ((i = in.read(b)) != -1) {
42 out.write(b, 0, i);
43 }
44 out.flush();
45 } finally {
46 in.close();
47 }
48 }
49
50 public static String getString(InputStream in, String charSet) throws IOException {
51 ByteArrayOutputStream out = new ByteArrayOutputStream();
52 copy(in, out, 4096);
53 return new String(out.toByteArray(), charSet);
54 }
55 }