javax.tools.ForwardingJavaFileObject Java Examples

The following examples show how to use javax.tools.ForwardingJavaFileObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecordingJavaFileManager.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, javax.tools.JavaFileObject.Kind kind, final FileObject sibling) throws IOException {
  JavaFileObject fileObject = super.getJavaFileForOutput(location, className, kind, sibling);
  return new ForwardingJavaFileObject<JavaFileObject>(fileObject) {
    @Override
    public OutputStream openOutputStream() throws IOException {
      record(sibling != null ? FileObjects.toFile(sibling) : null, FileObjects.toFile(fileObject));
      return new IncrementalFileOutputStream(FileObjects.toFile(this));
    }

    @Override
    public Writer openWriter() throws IOException {
      return encoding != null ? new OutputStreamWriter(openOutputStream(), encoding) : new OutputStreamWriter(openOutputStream());
    }
  };
}