KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > compiler > PackagerHelper


1 /*
2  * $Id: Packager.java 1671 2007-01-02 10:28:58Z dreil $
3  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
4  *
5  * http://www.izforge.com/izpack/
6  * http://developer.berlios.de/projects/izpack/
7  *
8  * Copyright 2006 Dennis Reil
9  *
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 JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28
29 /**
30  * Helper class for packager classes
31  * @author Dennis Reil, <Dennis.Reil@reddot.de>
32  */

33 public class PackagerHelper
34 {
35     /**
36      * Copies all the data from the specified input stream to the specified output stream.
37      *
38      * @param in the input stream to read
39      * @param out the output stream to write
40      * @return the total number of bytes copied
41      * @exception IOException if an I/O error occurs
42      */

43     public static long copyStream(InputStream JavaDoc in, OutputStream JavaDoc out) throws IOException JavaDoc
44     {
45         byte[] buffer = new byte[5120];
46         long bytesCopied = 0;
47         int bytesInBuffer;
48         while ((bytesInBuffer = in.read(buffer)) != -1)
49         {
50             out.write(buffer, 0, bytesInBuffer);
51             bytesCopied += bytesInBuffer;
52         }
53         return bytesCopied;
54     }
55 }
56
Popular Tags