src/share/classes/com/sun/tools/javac/file/BaseFileObject.java

changeset 400
35e29f51a7c3
parent 333
7c2d6da61646
child 404
14735c7932d7
child 415
49359d0e6a9c
     1.1 --- a/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Thu Sep 03 18:34:17 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/file/BaseFileObject.java	Tue Sep 08 11:12:13 2009 -0700
     1.3 @@ -29,6 +29,8 @@
     1.4  import java.io.IOException;
     1.5  import java.io.InputStreamReader;
     1.6  import java.io.Reader;
     1.7 +import java.net.URI;
     1.8 +import java.net.URISyntaxException;
     1.9  import java.nio.charset.CharsetDecoder;
    1.10  import javax.lang.model.element.Modifier;
    1.11  import javax.lang.model.element.NestingKind;
    1.12 @@ -93,7 +95,26 @@
    1.13          return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
    1.14      }
    1.15  
    1.16 +    protected static URI createJarUri(File jarFile, String entryName) {
    1.17 +        URI jarURI = jarFile.toURI().normalize();
    1.18 +        String separator = entryName.startsWith("/") ? "!" : "!/";
    1.19 +        try {
    1.20 +            // The jar URI convention appears to be not to re-encode the jarURI
    1.21 +            return new URI("jar:" + jarURI + separator + entryName);
    1.22 +        } catch (URISyntaxException e) {
    1.23 +            throw new CannotCreateUriError(jarURI + separator + entryName, e);
    1.24 +        }
    1.25 +    }
    1.26 +
    1.27 +    /** Used when URLSyntaxException is thrown unexpectedly during
    1.28 +     *  implementations of (Base)FileObject.toURI(). */
    1.29 +    protected static class CannotCreateUriError extends Error {
    1.30 +        private static final long serialVersionUID = 9101708840997613546L;
    1.31 +        public CannotCreateUriError(String value, Throwable cause) {
    1.32 +            super(value, cause);
    1.33 +        }
    1.34 +    }
    1.35 +
    1.36      /** The file manager that created this JavaFileObject. */
    1.37      protected final JavacFileManager fileManager;
    1.38 -
    1.39  }

mercurial