Java 类javax.tools.ForwardingFileObject 实例源码

项目:takari-lifecycle    文件:RecordingJavaFileManager.java   
@Override
public FileObject getFileForOutput(Location location, String packageName, String relativeName, final FileObject sibling) throws IOException {
  FileObject fileObject = super.getFileForOutput(location, packageName, relativeName, sibling);
  return new ForwardingFileObject<FileObject>(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());
    }
  };
}