]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/StreamUtils.java
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.io
.OutputStream
;
9 /** Utilities to be used when APache COmmons IO is not available. */
10 public class StreamUtils
{
11 private static final int DEFAULT_BUFFER_SIZE
= 1024 * 4;
13 /** @return the number of bytes */
14 public static Long
copy(InputStream in
, OutputStream out
)
17 byte[] buf
= new byte[DEFAULT_BUFFER_SIZE
];
19 int length
= in
.read(buf
);
22 out
.write(buf
, 0, length
);
23 count
= count
+ length
;
28 /** @return the number of chars */
29 public static Long
copy(Reader in
, Writer out
) throws IOException
{
31 char[] buf
= new char[DEFAULT_BUFFER_SIZE
];
33 int length
= in
.read(buf
);
36 out
.write(buf
, 0, length
);
37 count
= count
+ length
;
42 public static void closeQuietly(InputStream in
) {
46 } catch (Exception e
) {
51 public static void closeQuietly(OutputStream out
) {
55 } catch (Exception e
) {
60 public static void closeQuietly(Reader in
) {
64 } catch (Exception e
) {
69 public static void closeQuietly(Writer out
) {
73 } catch (Exception e
) {
78 private StreamUtils() {