]> git.argeo.org Git - lgpl/argeo-commons.git/blob - StreamUtils.java
10af68fa42f0862e72f477c18035b9af37eb55d2
[lgpl/argeo-commons.git] / StreamUtils.java
1 package org.argeo;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
6
7 /** Utilities to be used when APache COmmons IO is not available. */
8 public class StreamUtils {
9
10 public static void copy(InputStream in, OutputStream out)
11 throws IOException {
12 byte[] buf = new byte[8192];
13 while (true) {
14 int length = in.read(buf);
15 if (length < 0)
16 break;
17 out.write(buf, 0, length);
18 }
19 }
20
21 public static void closeQuietly(InputStream in) {
22 if (in != null)
23 try {
24 in.close();
25 } catch (Exception e) {
26 //
27 }
28 }
29
30 public static void closeQuietly(OutputStream out) {
31 if (out != null)
32 try {
33 out.close();
34 } catch (Exception e) {
35 //
36 }
37 }
38
39 private StreamUtils() {
40
41 }
42
43 }