1/*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package sun.tools.java;
27
28import java.io.File;
29import java.io.InputStream;
30import java.io.FileInputStream;
31import java.io.IOException;
32import java.util.zip.*;
33
34/**
35 * This class is used to represent a file loaded from the class path, and
36 * is a zip file entry.
37 *
38 * WARNING: The contents of this source file are not part of any
39 * supported API.  Code that depends on them does so at its own risk:
40 * they are subject to change or removal without notice.
41 */
42final
43class ZipClassFile extends ClassFile {
44    private final ZipFile zipFile;
45    private final ZipEntry zipEntry;
46
47    /**
48     * Constructor for instance representing a zip file entry
49     */
50    public ZipClassFile(ZipFile zf, ZipEntry ze) {
51        this.zipFile = zf;
52        this.zipEntry = ze;
53    }
54
55    @Override
56    public boolean isZipped() {
57        return true;
58    }
59
60    @Override
61    public InputStream getInputStream() throws IOException {
62        try {
63            return zipFile.getInputStream(zipEntry);
64        } catch (ZipException e) {
65            throw new IOException(e.getMessage());
66        }
67    }
68
69    @Override
70    public boolean exists() {
71        return true;
72    }
73
74    @Override
75    public boolean isDirectory() {
76        return zipEntry.getName().endsWith("/");
77    }
78
79    @Override
80    public long lastModified() {
81        return zipEntry.getTime();
82    }
83
84    @Override
85    public String getPath() {
86        return zipFile.getName() + "(" + zipEntry.getName() + ")";
87    }
88
89    @Override
90    public String getName() {
91        return zipEntry.getName();
92    }
93
94//JCOV
95    @Override
96    public String getAbsoluteName() {
97        return zipFile.getName() + "(" + zipEntry.getName() + ")";
98    }
99// end JCOV
100
101    @Override
102    public long length() {
103        return zipEntry.getSize();
104    }
105
106    @Override
107    public String toString() {
108        return zipEntry.toString();
109    }
110}
111