01: /*
02: * $Id: Packager.java 1671 2007-01-02 10:28:58Z dreil $
03: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
04: *
05: * http://izpack.org/
06: * http://izpack.codehaus.org/
07: *
08: * Copyright 2006 Dennis Reil
09: *
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: */
22:
23: package com.izforge.izpack.compiler;
24:
25: import java.io.IOException;
26: import java.io.InputStream;
27: import java.io.OutputStream;
28:
29: /**
30: * Helper class for packager classes
31: * @author Dennis Reil, <Dennis.Reil@reddot.de>
32: */
33: public class PackagerHelper {
34: /**
35: * Copies all the data from the specified input stream to the specified output stream.
36: *
37: * @param in the input stream to read
38: * @param out the output stream to write
39: * @return the total number of bytes copied
40: * @exception IOException if an I/O error occurs
41: */
42: public static long copyStream(InputStream in, OutputStream out)
43: throws IOException {
44: byte[] buffer = new byte[5120];
45: long bytesCopied = 0;
46: int bytesInBuffer;
47: while ((bytesInBuffer = in.read(buffer)) != -1) {
48: out.write(buffer, 0, bytesInBuffer);
49: bytesCopied += bytesInBuffer;
50: }
51: return bytesCopied;
52: }
53: }
|