]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.util/src/org/argeo/util/StreamUtils.java
1 package org
.argeo
.util
;
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. */
11 private static final int DEFAULT_BUFFER_SIZE
= 1024 * 4;
14 * APACHE COMMONS IO (inspired)
17 /** @return the number of bytes */
18 public static Long
copy(InputStream in
, OutputStream out
)
21 byte[] buf
= new byte[DEFAULT_BUFFER_SIZE
];
23 int length
= in
.read(buf
);
26 out
.write(buf
, 0, length
);
27 count
= count
+ length
;
32 /** @return the number of chars */
33 public static Long
copy(Reader in
, Writer out
) throws IOException
{
35 char[] buf
= new char[DEFAULT_BUFFER_SIZE
];
37 int length
= in
.read(buf
);
40 out
.write(buf
, 0, length
);
41 count
= count
+ length
;
46 public static void closeQuietly(InputStream in
) {
50 } catch (Exception e
) {
55 public static void closeQuietly(OutputStream out
) {
59 } catch (Exception e
) {
64 public static void closeQuietly(Reader in
) {
68 } catch (Exception e
) {
73 public static void closeQuietly(Writer out
) {
77 } catch (Exception e
) {