KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > shared > ArchivistUtils


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.util.shared;
25
26 import java.io.EOFException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.OutputStream JavaDoc;
30
31 /**
32  * This class contains utility methods that handles the archives.
33  *
34  * @author Deployment Dev Team
35  * @version
36  */

37 public class ArchivistUtils {
38
39     /**
40      * Utility method that eads the input stream fully and writes the bytes to
41      * the current entry in the output stream.
42      */

43     public static void copy(InputStream JavaDoc is, OutputStream JavaDoc os) throws IOException JavaDoc {
44         copyWithoutClose(is, os);
45         is.close();
46         os.close();
47     }
48
49     /**
50      * Utility method that eads the input stream fully and writes the bytes to
51      * the current entry in the output stream.
52      */

53     public static void copyWithoutClose(InputStream JavaDoc is, OutputStream JavaDoc os) throws IOException JavaDoc {
54         byte[] buf = new byte[4096];
55         int len = 0;
56         while (len != -1) {
57             try {
58                 len = is.read(buf, 0, buf.length);
59             } catch (EOFException JavaDoc eof){
60                 break;
61             }
62
63             if(len != -1) {
64                 os.write(buf, 0, len);
65             }
66         }
67         os.flush();
68     }
69 }
70
Popular Tags