KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > JarEntrySource


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 package com.sun.enterprise.util;
24
25 import java.io.InputStream JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.File JavaDoc;
28
29 public class JarEntrySource {
30     public JarEntrySource(File JavaDoc file) {
31     this.markOnly = false;
32     this.name = file.getPath().replace(File.separatorChar, '/');
33     this.file = file;
34     }
35
36     public JarEntrySource(String JavaDoc name, File JavaDoc file) {
37     this.markOnly = false;
38     this.name = name;
39     this.file = file;
40     }
41
42     public JarEntrySource(String JavaDoc name, InputStream JavaDoc is) {
43     this.markOnly = false;
44     this.name = name;
45     this.is = is;
46     }
47
48     public JarEntrySource(String JavaDoc name) {
49     this.markOnly = true;
50     this.name = name;
51     }
52     /**
53      * Accessors
54      */

55     public boolean isMarkOnly() {
56     return markOnly;
57     }
58
59     public long getTime() {
60     if (file != null) {
61         return file.lastModified();
62     } else {
63         return 0; // ??
64
}
65     }
66
67     public long getLength() {
68     if (file != null) {
69         return file.length();
70     } else {
71         return 0; // ??
72
}
73     }
74
75     public String JavaDoc getName() {
76     return name;
77     }
78
79     public InputStream JavaDoc getInputStream() {
80     if (file != null) {
81         try {
82         return new FileInputStream JavaDoc(file);
83         } catch (Exception JavaDoc ex) {
84         return null;
85         }
86     } else {
87         return is;
88     }
89     }
90
91     private boolean markOnly; // only mark in the ZIP
92
private String JavaDoc name; // the name of this entry
93
private InputStream JavaDoc is; // the input stream for the entry
94
private File JavaDoc file; // if a file
95
private long modifiedTime; // if an inputstream
96

97     public String JavaDoc toString() {
98     return file == null ? getName() : file.toString();
99     }
100 }
101
Popular Tags