langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
changeset 3782 ae62279eeb46
parent 3656 d4e34b76b0c3
child 3995 73af8b6fb8bc
child 3890 b53fced26fa4
equal deleted inserted replaced
3781:cad98ced28c5 3782:ae62279eeb46
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.javac.file;
    26 package com.sun.tools.javac.file;
    27 
    27 
    28 import java.io.ByteArrayOutputStream;
    28 import java.io.ByteArrayOutputStream;
       
    29 import java.io.Closeable;
    29 import java.io.File;
    30 import java.io.File;
    30 import java.io.FileInputStream;
    31 import java.io.FileInputStream;
    31 import java.io.FileNotFoundException;
    32 import java.io.FileNotFoundException;
    32 import java.io.IOException;
    33 import java.io.IOException;
    33 import java.io.InputStream;
    34 import java.io.InputStream;
    34 import java.io.OutputStreamWriter;
    35 import java.io.OutputStreamWriter;
    35 import java.lang.ref.SoftReference;
    36 import java.lang.ref.SoftReference;
    36 import java.lang.reflect.Constructor;
    37 import java.lang.reflect.Constructor;
    37 import java.net.MalformedURLException;
    38 import java.net.MalformedURLException;
    38 import java.net.URI;
    39 import java.net.URI;
       
    40 import java.net.URISyntaxException;
    39 import java.net.URL;
    41 import java.net.URL;
    40 import java.net.URLClassLoader;
    42 import java.net.URLClassLoader;
    41 import java.nio.ByteBuffer;
    43 import java.nio.ByteBuffer;
    42 import java.nio.CharBuffer;
    44 import java.nio.CharBuffer;
    43 import java.nio.channels.FileChannel;
    45 import java.nio.channels.FileChannel;
    75 import com.sun.tools.javac.util.List;
    77 import com.sun.tools.javac.util.List;
    76 import com.sun.tools.javac.util.ListBuffer;
    78 import com.sun.tools.javac.util.ListBuffer;
    77 import com.sun.tools.javac.util.Log;
    79 import com.sun.tools.javac.util.Log;
    78 import com.sun.tools.javac.util.Options;
    80 import com.sun.tools.javac.util.Options;
    79 
    81 
    80 import java.io.Closeable;
       
    81 import static javax.tools.StandardLocation.*;
    82 import static javax.tools.StandardLocation.*;
    82 import static com.sun.tools.javac.main.OptionName.*;
    83 import static com.sun.tools.javac.main.OptionName.*;
    83 
    84 
    84 /**
    85 /**
    85  * This class provides access to the source, class and other files
    86  * This class provides access to the source, class and other files
   435 
   436 
   436         public Set<RelativeDirectory> getSubdirectories() {
   437         public Set<RelativeDirectory> getSubdirectories() {
   437             return Collections.emptySet();
   438             return Collections.emptySet();
   438         }
   439         }
   439 
   440 
       
   441         @Override
   440         public String toString() {
   442         public String toString() {
   441             return "MissingArchive[" + zipFileName + "]";
   443             return "MissingArchive[" + zipFileName + "]";
   442         }
   444         }
   443     }
   445     }
   444 
   446 
   652     }
   654     }
   653 
   655 
   654     private final ByteBufferCache byteBufferCache;
   656     private final ByteBufferCache byteBufferCache;
   655 
   657 
   656     CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
   658     CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
   657         Charset charset = (this.charset == null)
   659         Charset cs = (this.charset == null)
   658             ? Charset.forName(encodingName)
   660             ? Charset.forName(encodingName)
   659             : this.charset;
   661             : this.charset;
   660         CharsetDecoder decoder = charset.newDecoder();
   662         CharsetDecoder decoder = cs.newDecoder();
   661 
   663 
   662         CodingErrorAction action;
   664         CodingErrorAction action;
   663         if (ignoreEncodingErrors)
   665         if (ignoreEncodingErrors)
   664             action = CodingErrorAction.REPLACE;
   666             action = CodingErrorAction.REPLACE;
   665         else
   667         else
   890         throws IOException
   892         throws IOException
   891     {
   893     {
   892         nullCheck(location);
   894         nullCheck(location);
   893         // validatePackageName(packageName);
   895         // validatePackageName(packageName);
   894         nullCheck(packageName);
   896         nullCheck(packageName);
   895         if (!isRelativeUri(URI.create(relativeName))) // FIXME 6419701
   897         if (!isRelativeUri(relativeName))
   896             throw new IllegalArgumentException("Invalid relative name: " + relativeName);
   898             throw new IllegalArgumentException("Invalid relative name: " + relativeName);
   897         RelativeFile name = packageName.length() == 0
   899         RelativeFile name = packageName.length() == 0
   898             ? new RelativeFile(relativeName)
   900             ? new RelativeFile(relativeName)
   899             : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
   901             : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
   900         return getFileForInput(location, name);
   902         return getFileForInput(location, name);
   944         throws IOException
   946         throws IOException
   945     {
   947     {
   946         nullCheck(location);
   948         nullCheck(location);
   947         // validatePackageName(packageName);
   949         // validatePackageName(packageName);
   948         nullCheck(packageName);
   950         nullCheck(packageName);
   949         if (!isRelativeUri(URI.create(relativeName))) // FIXME 6419701
   951         if (!isRelativeUri(relativeName))
   950             throw new IllegalArgumentException("relativeName is invalid");
   952             throw new IllegalArgumentException("relativeName is invalid");
   951         RelativeFile name = packageName.length() == 0
   953         RelativeFile name = packageName.length() == 0
   952             ? new RelativeFile(relativeName)
   954             ? new RelativeFile(relativeName)
   953             : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
   955             : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName);
   954         return getFileForOutput(location, name, sibling);
   956         return getFileForOutput(location, name, sibling);
  1083             return false;
  1085             return false;
  1084         char first = path.charAt(0);
  1086         char first = path.charAt(0);
  1085         return first != '.' && first != '/';
  1087         return first != '.' && first != '/';
  1086     }
  1088     }
  1087 
  1089 
       
  1090     // Convenience method
       
  1091     protected static boolean isRelativeUri(String u) {
       
  1092         try {
       
  1093             return isRelativeUri(new URI(u));
       
  1094         } catch (URISyntaxException e) {
       
  1095             return false;
       
  1096         }
       
  1097     }
       
  1098 
  1088     /**
  1099     /**
  1089      * Converts a relative file name to a relative URI.  This is
  1100      * Converts a relative file name to a relative URI.  This is
  1090      * different from File.toURI as this method does not canonicalize
  1101      * different from File.toURI as this method does not canonicalize
  1091      * the file before creating the URI.  Furthermore, no schema is
  1102      * the file before creating the URI.  Furthermore, no schema is
  1092      * used.
  1103      * used.
  1097      * javax.tools.JavaFileManager#getFileForInput}
  1108      * javax.tools.JavaFileManager#getFileForInput}
  1098      */
  1109      */
  1099     public static String getRelativeName(File file) {
  1110     public static String getRelativeName(File file) {
  1100         if (!file.isAbsolute()) {
  1111         if (!file.isAbsolute()) {
  1101             String result = file.getPath().replace(File.separatorChar, '/');
  1112             String result = file.getPath().replace(File.separatorChar, '/');
  1102             if (JavacFileManager.isRelativeUri(URI.create(result))) // FIXME 6419701
  1113             if (isRelativeUri(result))
  1103                 return result;
  1114                 return result;
  1104         }
  1115         }
  1105         throw new IllegalArgumentException("Invalid relative path: " + file);
  1116         throw new IllegalArgumentException("Invalid relative path: " + file);
  1106     }
  1117     }
  1107 
  1118