code: public void writeTo(Path directory) throws IOException {
      checkArgument(Files.notExists(directory) || Files.isDirectory(directory),
          "path %s exists but is not a directory.", directory);
      Path outputDirectory = directory;
      if (!packageName.isEmpty()) {
        for (String packageComponent : packageName.split("\\.")) {
          outputDirectory = outputDirectory.resolve(packageComponent);
        }
        Files.createDirectories(outputDirectory);
      }
  
      Path outputPath = outputDirectory.resolve(typeSpec.name + ".java");
      try (Writer writer = new OutputStreamWriter(Files.newOutputStream(outputPath), UTF_8)) {
        writeTo(writer);
      }
    }
docs: Writes this to {@code directory} as UTF-8 using the standard directory structure.