langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java
author mchung
Fri, 20 Jun 2014 13:36:10 -0700
changeset 25303 5f9e68207588
parent 23810 b92eb80925f0
permissions -rw-r--r--
8044063: Remove com.sun.java.browser.* from jdk repo Reviewed-by: darcy, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
     1
/*
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 22159
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
     4
 *
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    10
 *
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    15
 * accompanied this code).
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    16
 *
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4073
diff changeset
    23
 * questions.
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    24
 */
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    25
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.file;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    27
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    28
import java.io.IOException;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    29
import java.util.Set;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    30
import javax.tools.JavaFileObject;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    31
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    32
import java.io.ByteArrayInputStream;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    33
import java.io.File;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    34
import java.io.InputStream;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    35
import java.io.OutputStream;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    36
import java.io.Writer;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    37
import java.net.URI;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    38
import java.nio.ByteBuffer;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    39
import java.nio.CharBuffer;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    40
import java.nio.charset.CharsetDecoder;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    41
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    42
import com.sun.tools.javac.file.JavacFileManager.Archive;
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    43
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    44
import com.sun.tools.javac.file.RelativePath.RelativeFile;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 5847
diff changeset
    45
import com.sun.tools.javac.util.Assert;
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    46
import com.sun.tools.javac.util.List;
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    47
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1205
diff changeset
    48
/**
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    49
 * <p><b>This is NOT part of any supported API.
3380
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1205
diff changeset
    50
 * If you write code that depends on this, you do so at your own risk.
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1205
diff changeset
    51
 * This code and its internal interfaces are subject to change or
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1205
diff changeset
    52
 * deletion without notice.</b>
a6c2bcab0fec 6865399: some javac files are missing Sun internal API comment
jjg
parents: 1205
diff changeset
    53
 */
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    54
public class ZipFileIndexArchive implements Archive {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    55
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    56
    private final ZipFileIndex zfIndex;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    57
    private JavacFileManager fileManager;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    58
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    59
    public ZipFileIndexArchive(JavacFileManager fileManager, ZipFileIndex zdir) throws IOException {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    60
        super();
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    61
        this.fileManager = fileManager;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    62
        this.zfIndex = zdir;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    63
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    64
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    65
    public boolean contains(RelativePath name) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    66
        return zfIndex.contains(name);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    67
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    68
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    69
    public List<String> getFiles(RelativeDirectory subdirectory) {
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    70
        return zfIndex.getFiles(subdirectory);
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    71
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    72
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    73
    public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    74
        RelativeFile fullZipFileName = new RelativeFile(subdirectory, file);
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    75
        ZipFileIndex.Entry entry = zfIndex.getZipIndexEntry(fullZipFileName);
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3380
diff changeset
    76
        JavaFileObject ret = new ZipFileIndexFileObject(fileManager, zfIndex, entry, zfIndex.getZipFile());
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    77
        return ret;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    78
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    79
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    80
    public Set<RelativeDirectory> getSubdirectories() {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    81
        return zfIndex.getAllDirectories();
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    82
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    83
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    84
    public void close() throws IOException {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    85
        zfIndex.close();
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    86
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    87
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3380
diff changeset
    88
    @Override
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    89
    public String toString() {
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    90
        return "ZipFileIndexArchive[" + zfIndex + "]";
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    91
    }
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
    92
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    93
    /**
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    94
     * A subclass of JavaFileObject representing zip entries using the com.sun.tools.javac.file.ZipFileIndex implementation.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    95
     */
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    96
    public static class ZipFileIndexFileObject extends BaseFileObject {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    97
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    98
        /** The entry's name.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
    99
         */
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   100
        private String name;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   101
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   102
        /** The zipfile containing the entry.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   103
         */
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   104
        ZipFileIndex zfIndex;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   105
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   106
        /** The underlying zip entry object.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   107
         */
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   108
        ZipFileIndex.Entry entry;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   109
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   110
        /** The name of the zip file where this entry resides.
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   111
         */
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3380
diff changeset
   112
        File zipName;
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   113
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   114
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3380
diff changeset
   115
        ZipFileIndexFileObject(JavacFileManager fileManager, ZipFileIndex zfIndex, ZipFileIndex.Entry entry, File zipFileName) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   116
            super(fileManager);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   117
            this.name = entry.getFileName();
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   118
            this.zfIndex = zfIndex;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   119
            this.entry = entry;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   120
            this.zipName = zipFileName;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   121
        }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   122
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   123
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   124
        public URI toUri() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   125
            return createJarUri(zipName, getPrefixedEntryName());
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   126
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   127
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   128
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   129
        public String getName() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   130
            return zipName + "(" + getPrefixedEntryName() + ")";
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   131
        }
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   132
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   133
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   134
        public String getShortName() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   135
            return zipName.getName() + "(" + entry.getName() + ")";
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   136
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   137
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   138
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   139
        public JavaFileObject.Kind getKind() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   140
            return getKind(entry.getName());
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   141
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   142
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   143
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   144
        public InputStream openInputStream() throws IOException {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 22159
diff changeset
   145
            Assert.checkNonNull(entry); // see constructor
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 22159
diff changeset
   146
            return new ByteArrayInputStream(zfIndex.read(entry));
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   147
        }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   148
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3380
diff changeset
   149
        @Override
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   150
        public OutputStream openOutputStream() throws IOException {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   151
            throw new UnsupportedOperationException();
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   152
        }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   153
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 3380
diff changeset
   154
        @Override
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   155
        public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   156
            CharBuffer cb = fileManager.getCachedContent(this);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   157
            if (cb == null) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 8032
diff changeset
   158
                try (InputStream in = new ByteArrayInputStream(zfIndex.read(entry))) {
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   159
                    ByteBuffer bb = fileManager.makeByteBuffer(in);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   160
                    JavaFileObject prev = fileManager.log.useSource(this);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   161
                    try {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   162
                        cb = fileManager.decode(bb, ignoreEncodingErrors);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   163
                    } finally {
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   164
                        fileManager.log.useSource(prev);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   165
                    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   166
                    fileManager.recycleByteBuffer(bb); // save for next time
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   167
                    if (!ignoreEncodingErrors)
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   168
                        fileManager.cache(this, cb);
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   169
                }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   170
            }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   171
            return cb;
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   172
        }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   173
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   174
        @Override
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   175
        public Writer openWriter() throws IOException {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   176
            throw new UnsupportedOperationException();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   177
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   178
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   179
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   180
        public long getLastModified() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   181
            return entry.getLastModified();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   182
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   183
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   184
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   185
        public boolean delete() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   186
            throw new UnsupportedOperationException();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   187
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   188
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   189
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   190
        protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   191
            return fileManager.getDecoder(fileManager.getEncodingName(), ignoreEncodingErrors);
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   192
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   193
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   194
        @Override
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   195
        protected String inferBinaryName(Iterable<? extends File> path) {
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   196
            String entryName = entry.getName();
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   197
            if (zfIndex.symbolFilePrefix != null) {
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
   198
                String prefix = zfIndex.symbolFilePrefix.path;
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   199
                if (entryName.startsWith(prefix))
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   200
                    entryName = entryName.substring(prefix.length());
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   201
            }
1205
b316e32eb90c 6508981: cleanup file separator handling in JavacFileManager
jjg
parents: 810
diff changeset
   202
            return removeExtension(entryName).replace('/', '.');
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   203
        }
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   204
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   205
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   206
        public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   207
            cn.getClass(); // null check
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   208
            if (k == Kind.OTHER && getKind() != k)
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   209
                return false;
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   210
            return name.equals(cn + k.extension);
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   211
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   212
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   213
        /**
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   214
         * Check if two file objects are equal.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   215
         * Two ZipFileIndexFileObjects are equal if the absolute paths of the underlying
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   216
         * zip files are equal and if the paths within those zip files are equal.
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   217
         */
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   218
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   219
        public boolean equals(Object other) {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   220
            if (this == other)
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   221
                return true;
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   222
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   223
            if (!(other instanceof ZipFileIndexFileObject))
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   224
                return false;
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   225
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   226
            ZipFileIndexFileObject o = (ZipFileIndexFileObject) other;
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   227
            return zfIndex.getAbsoluteFile().equals(o.zfIndex.getAbsoluteFile())
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   228
                    && name.equals(o.name);
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   229
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   230
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   231
        @Override
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   232
        public int hashCode() {
4073
9788f4549740 6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents: 3998
diff changeset
   233
            return zfIndex.getAbsoluteFile().hashCode() + name.hashCode();
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   234
        }
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   235
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   236
        private String getPrefixedEntryName() {
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   237
            if (zfIndex.symbolFilePrefix != null)
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   238
                return zfIndex.symbolFilePrefix.path + entry.getName();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   239
            else
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   240
                return entry.getName();
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3782
diff changeset
   241
        }
810
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   242
    }
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   243
e4b6a6d206e6 6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff changeset
   244
}