Debian Codegraph @

src/main/java/net/sf/antcontrib/antserver/Util.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package net.sf.antcontrib.antserver;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21
22
23 /****************************************************************************
24 * Place class description here.
25 *
26 * @author <a href='mailto:[email protected]'>Matthew Inger</a>
27 * @author <additional author>
28 *
29 * @since
30 *
31 ****************************************************************************/
32
33
34 public class Util
35 {
36 public static final int CHUNK = 10*1024;
37
38 public static final void transferBytes(InputStream input,
39 long length,
40 OutputStream output,
41 boolean closeInput)
42 throws IOException
43 {
44
45 byte b[] = new byte[CHUNK];
46 int read = 0;
47 int totalread = 0;
48
49 while (totalread < length)
50 {
51 int toRead = (int)Math.min(CHUNK, length - totalread);
52 read = input.read(b, 0, toRead);
53 output.write(b, 0, read);
54 totalread += read;
55 }
56
57 try
58 {
59 if (closeInput)
60 input.close();
61 }
62 catch (IOException e)
63 {
64 // ; gulp
65 }
66 }
67 }