40 import java.nio.CharBuffer; |
40 import java.nio.CharBuffer; |
41 import java.nio.charset.CharsetDecoder; |
41 import java.nio.charset.CharsetDecoder; |
42 import javax.tools.JavaFileObject; |
42 import javax.tools.JavaFileObject; |
43 import java.text.Normalizer; |
43 import java.text.Normalizer; |
44 |
44 |
|
45 import com.sun.tools.javac.util.DefinedBy; |
|
46 import com.sun.tools.javac.util.DefinedBy.Api; |
|
47 |
45 /** |
48 /** |
46 * A subclass of JavaFileObject representing regular files. |
49 * A subclass of JavaFileObject representing regular files. |
47 * |
50 * |
48 * <p><b>This is NOT part of any supported API. |
51 * <p><b>This is NOT part of any supported API. |
49 * If you write code that depends on this, you do so at your own risk. |
52 * If you write code that depends on this, you do so at your own risk. |
73 this.file = f; |
76 this.file = f; |
74 if (f.lastModified() > System.currentTimeMillis()) |
77 if (f.lastModified() > System.currentTimeMillis()) |
75 fileManager.log.warning("file.from.future", f); |
78 fileManager.log.warning("file.from.future", f); |
76 } |
79 } |
77 |
80 |
78 @Override |
81 @Override @DefinedBy(Api.COMPILER) |
79 public URI toUri() { |
82 public URI toUri() { |
80 return file.toURI().normalize(); |
83 return file.toURI().normalize(); |
81 } |
84 } |
82 |
85 |
83 @Override |
86 @Override @DefinedBy(Api.COMPILER) |
84 public String getName() { |
87 public String getName() { |
85 return file.getPath(); |
88 return file.getPath(); |
86 } |
89 } |
87 |
90 |
88 @Override |
91 @Override |
89 public String getShortName() { |
92 public String getShortName() { |
90 return name; |
93 return name; |
91 } |
94 } |
92 |
95 |
93 @Override |
96 @Override @DefinedBy(Api.COMPILER) |
94 public JavaFileObject.Kind getKind() { |
97 public JavaFileObject.Kind getKind() { |
95 return getKind(name); |
98 return getKind(name); |
96 } |
99 } |
97 |
100 |
98 @Override |
101 @Override @DefinedBy(Api.COMPILER) |
99 public InputStream openInputStream() throws IOException { |
102 public InputStream openInputStream() throws IOException { |
100 return new FileInputStream(file); |
103 return new FileInputStream(file); |
101 } |
104 } |
102 |
105 |
103 @Override |
106 @Override @DefinedBy(Api.COMPILER) |
104 public OutputStream openOutputStream() throws IOException { |
107 public OutputStream openOutputStream() throws IOException { |
105 fileManager.flushCache(this); |
108 fileManager.flushCache(this); |
106 ensureParentDirectoriesExist(); |
109 ensureParentDirectoriesExist(); |
107 return new FileOutputStream(file); |
110 return new FileOutputStream(file); |
108 } |
111 } |
109 |
112 |
110 @Override |
113 @Override @DefinedBy(Api.COMPILER) |
111 public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
114 public CharBuffer getCharContent(boolean ignoreEncodingErrors) throws IOException { |
112 CharBuffer cb = fileManager.getCachedContent(this); |
115 CharBuffer cb = fileManager.getCachedContent(this); |
113 if (cb == null) { |
116 if (cb == null) { |
114 try (InputStream in = new FileInputStream(file)) { |
117 try (InputStream in = new FileInputStream(file)) { |
115 ByteBuffer bb = fileManager.makeByteBuffer(in); |
118 ByteBuffer bb = fileManager.makeByteBuffer(in); |
126 } |
129 } |
127 } |
130 } |
128 return cb; |
131 return cb; |
129 } |
132 } |
130 |
133 |
131 @Override |
134 @Override @DefinedBy(Api.COMPILER) |
132 public Writer openWriter() throws IOException { |
135 public Writer openWriter() throws IOException { |
133 fileManager.flushCache(this); |
136 fileManager.flushCache(this); |
134 ensureParentDirectoriesExist(); |
137 ensureParentDirectoriesExist(); |
135 return new OutputStreamWriter(new FileOutputStream(file), fileManager.getEncodingName()); |
138 return new OutputStreamWriter(new FileOutputStream(file), fileManager.getEncodingName()); |
136 } |
139 } |
137 |
140 |
138 @Override |
141 @Override @DefinedBy(Api.COMPILER) |
139 public long getLastModified() { |
142 public long getLastModified() { |
140 return file.lastModified(); |
143 return file.lastModified(); |
141 } |
144 } |
142 |
145 |
143 @Override |
146 @Override @DefinedBy(Api.COMPILER) |
144 public boolean delete() { |
147 public boolean delete() { |
145 return file.delete(); |
148 return file.delete(); |
146 } |
149 } |
147 |
150 |
148 @Override |
151 @Override |