855 for (String part : name.split("[./\\\\]")) {
856 if (RESERVED_NAMES.contains(part.toLowerCase(Locale.US))) {
857 throw new IllegalArgumentException("Name: " + name + " is" +
858 "a reserved name on Windows, " +
859 "and will not work!");
860 }
861 }
862 }
863
864 public static class MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> {
865 private interface Content {
866 byte[] getBytes();
867 String getString();
868 }
869
870 /**
871 * Maps binary class names to generated content.
872 */
873 private final Map<Location, Map<String, Content>> files;
874
875 /**
876 * Constructs a memory file manager which stores output files in memory,
877 * and delegates to a default file manager for input files.
878 */
879 public MemoryFileManager() {
880 this(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null));
881 }
882
883 /**
884 * Constructs a memory file manager which stores output files in memory,
885 * and delegates to a specified file manager for input files.
886 *
887 * @param fileManager the file manager to be used for input files
888 */
889 public MemoryFileManager(JavaFileManager fileManager) {
890 super(fileManager);
891 files = new HashMap<>();
892 }
893
894 @Override
895 public JavaFileObject getJavaFileForOutput(Location location,
896 String name,
897 JavaFileObject.Kind kind,
898 FileObject sibling)
899 {
900 return new MemoryFileObject(location, name, kind);
901 }
902
903 /**
904 * Returns the set of names of files that have been written to a given
905 * location.
906 *
907 * @param location the location
908 * @return the set of file names
909 */
910 public Set<String> getFileNames(Location location) {
911 Map<String, Content> filesForLocation = files.get(location);
|
855 for (String part : name.split("[./\\\\]")) {
856 if (RESERVED_NAMES.contains(part.toLowerCase(Locale.US))) {
857 throw new IllegalArgumentException("Name: " + name + " is" +
858 "a reserved name on Windows, " +
859 "and will not work!");
860 }
861 }
862 }
863
864 public static class MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> {
865 private interface Content {
866 byte[] getBytes();
867 String getString();
868 }
869
870 /**
871 * Maps binary class names to generated content.
872 */
873 private final Map<Location, Map<String, Content>> files;
874
875 /**
876 * Whether the delegate is owned by this instance and should be closed when
877 * this instance is closed.
878 */
879 private final boolean shouldClose;
880
881 /**
882 * Constructs a memory file manager which stores output files in memory,
883 * and delegates to a default file manager for input files.
884 */
885 public MemoryFileManager() {
886 this(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null), true);
887 }
888
889 /**
890 * Constructs a memory file manager which stores output files in memory,
891 * and delegates to a specified file manager for input files.
892 *
893 * @param fileManager the file manager to be used for input files
894 * @param shouldClose whether the delegate file manager should be closed
895 * when this instance is closed
896 */
897 public MemoryFileManager(JavaFileManager fileManager, boolean shouldClose) {
898 super(fileManager);
899 this.files = new HashMap<>();
900 this.shouldClose = shouldClose;
901 }
902
903 @Override
904 public void close() throws IOException {
905 if (shouldClose) {
906 super.close();
907 }
908 }
909
910 @Override
911 public JavaFileObject getJavaFileForOutput(Location location,
912 String name,
913 JavaFileObject.Kind kind,
914 FileObject sibling)
915 {
916 return new MemoryFileObject(location, name, kind);
917 }
918
919 /**
920 * Returns the set of names of files that have been written to a given
921 * location.
922 *
923 * @param location the location
924 * @return the set of file names
925 */
926 public Set<String> getFileNames(Location location) {
927 Map<String, Content> filesForLocation = files.get(location);
|