< prev index next >

test/langtools/tools/lib/toolbox/ToolBox.java

Print this page

 834         for (String part : name.split("[./\\\\]")) {
 835             if (RESERVED_NAMES.contains(part.toLowerCase(Locale.US))) {
 836                 throw new IllegalArgumentException("Name: " + name + " is" +
 837                                                    "a reserved name on Windows, " +
 838                                                    "and will not work!");
 839             }
 840         }
 841     }
 842 
 843     public static class MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> {
 844         private interface Content {
 845             byte[] getBytes();
 846             String getString();
 847         }
 848 
 849         /**
 850          * Maps binary class names to generated content.
 851          */
 852         private final Map<Location, Map<String, Content>> files;
 853 






 854         /**
 855          * Constructs a memory file manager which stores output files in memory,
 856          * and delegates to a default file manager for input files.
 857          */
 858         public MemoryFileManager() {
 859             this(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null));
 860         }
 861 
 862         /**
 863          * Constructs a memory file manager which stores output files in memory,
 864          * and delegates to a specified file manager for input files.
 865          *
 866          * @param fileManager the file manager to be used for input files


 867          */
 868         public MemoryFileManager(JavaFileManager fileManager) {
 869             super(fileManager);
 870             files = new HashMap<>();








 871         }
 872 
 873         @Override
 874         public JavaFileObject getJavaFileForOutput(Location location,
 875                                                    String name,
 876                                                    JavaFileObject.Kind kind,
 877                                                    FileObject sibling)
 878         {
 879             return new MemoryFileObject(location, name, kind);
 880         }
 881 
 882         /**
 883          * Returns the set of names of files that have been written to a given
 884          * location.
 885          *
 886          * @param location the location
 887          * @return the set of file names
 888          */
 889         public Set<String> getFileNames(Location location) {
 890             Map<String, Content> filesForLocation = files.get(location);

 834         for (String part : name.split("[./\\\\]")) {
 835             if (RESERVED_NAMES.contains(part.toLowerCase(Locale.US))) {
 836                 throw new IllegalArgumentException("Name: " + name + " is" +
 837                                                    "a reserved name on Windows, " +
 838                                                    "and will not work!");
 839             }
 840         }
 841     }
 842 
 843     public static class MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> {
 844         private interface Content {
 845             byte[] getBytes();
 846             String getString();
 847         }
 848 
 849         /**
 850          * Maps binary class names to generated content.
 851          */
 852         private final Map<Location, Map<String, Content>> files;
 853 
 854         /**
 855          * Whether the delegate is owned by this instance and should be closed when
 856          * this instance is closed.
 857          */
 858         private final boolean shouldClose;
 859 
 860         /**
 861          * Constructs a memory file manager which stores output files in memory,
 862          * and delegates to a default file manager for input files.
 863          */
 864         public MemoryFileManager() {
 865             this(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null), true);
 866         }
 867 
 868         /**
 869          * Constructs a memory file manager which stores output files in memory,
 870          * and delegates to a specified file manager for input files.
 871          *
 872          * @param fileManager the file manager to be used for input files
 873          * @param shouldClose whether the delegate file manager should be closed
 874          *     when this instance is closed
 875          */
 876         public MemoryFileManager(JavaFileManager fileManager, boolean shouldClose) {
 877             super(fileManager);
 878             this.files = new HashMap<>();
 879             this.shouldClose = shouldClose;
 880         }
 881 
 882         @Override
 883         public void close() throws IOException {
 884             if (shouldClose) {
 885                 super.close();
 886             }
 887         }
 888 
 889         @Override
 890         public JavaFileObject getJavaFileForOutput(Location location,
 891                                                    String name,
 892                                                    JavaFileObject.Kind kind,
 893                                                    FileObject sibling)
 894         {
 895             return new MemoryFileObject(location, name, kind);
 896         }
 897 
 898         /**
 899          * Returns the set of names of files that have been written to a given
 900          * location.
 901          *
 902          * @param location the location
 903          * @return the set of file names
 904          */
 905         public Set<String> getFileNames(Location location) {
 906             Map<String, Content> filesForLocation = files.get(location);
< prev index next >