]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.util/src/org/argeo/util/StreamUtils.java
1cfa5b2206fe0c83ff044d6871277b9c4cdf92f0
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.util
;
18 import java
.io
.IOException
;
19 import java
.io
.InputStream
;
20 import java
.io
.OutputStream
;
21 import java
.io
.Reader
;
22 import java
.io
.Writer
;
24 /** Utilities to be used when APache COmmons IO is not available. */
26 private static final int DEFAULT_BUFFER_SIZE
= 1024 * 4;
29 * APACHE COMMONS IO (inspired)
32 /** @return the number of bytes */
33 public static Long
copy(InputStream in
, OutputStream out
)
36 byte[] buf
= new byte[DEFAULT_BUFFER_SIZE
];
38 int length
= in
.read(buf
);
41 out
.write(buf
, 0, length
);
42 count
= count
+ length
;
47 /** @return the number of chars */
48 public static Long
copy(Reader in
, Writer out
) throws IOException
{
50 char[] buf
= new char[DEFAULT_BUFFER_SIZE
];
52 int length
= in
.read(buf
);
55 out
.write(buf
, 0, length
);
56 count
= count
+ length
;
61 public static void closeQuietly(InputStream in
) {
65 } catch (Exception e
) {
70 public static void closeQuietly(OutputStream out
) {
74 } catch (Exception e
) {
79 public static void closeQuietly(Reader in
) {
83 } catch (Exception e
) {
88 public static void closeQuietly(Writer out
) {
92 } catch (Exception e
) {