generator/src/main/java/org/ovirt/sdk/go/GoBuffer.java
/**
     * Creates a {@code .go} source file and writes the source. The required intermediate directories will be created
     * if they don't exist.
     *
     * @param dir the base directory for the source code
     * @throws IOException if something fails while creating or writing the file
     */
Creates a  .go source file and writes the source. The required intermediate directories will be created
if they don't exist.

@param dir the base directory for the source code
@throws IOException if something fails while creating or writing the file
Creates a . go source file and writes the source . The required intermediate directories will be created if they don ' t exist . @param dir the base directory for the source code @throws IOException if something fails while creating or writing the file
public void write(File dir) throws IOException {
        if (fileName == null) {
            fileName = packageName;
        }
        File file = new File(dir, fileName + ".go");
        File parent = file.getParentFile();
        FileUtils.forceMkdir(parent);
        System.out.println("Writing file \"" + file.getAbsolutePath() + "\".");
        try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
            writer.write(toString());
        }
        Process gofmt = new ProcessBuilder()
            .command("gofmt", "-w", file.getAbsolutePath())
            .inheritIO()
            .start();
        try {
            int code = gofmt.waitFor();
            if (code != 0) {
                throw new IOException(
                    "Execution of \"gofmt\" on file \"" + file.getAbsolutePath() + "\" failed with exit code " + code
                );
            }
        }
        catch (InterruptedException exception) {
            throw new IOException(
                "Interrupted while waiting for to execute \"gofmt\" on file \"" + file.getAbsolutePath() + "\"",
                exception
            );
        }
    }
public void write ( File dir ) throws IOException { if ( fileName == null ) { fileName = packageName ; } File file = new File ( dir , fileName + ".go" ) ; File parent = file . getParentFile ( ) ; FileUtils . forceMkdir ( parent ) ; System . out . println ( "Writing file \"" + file . getAbsolutePath ( ) + "\"." ) ; try ( Writer writer = new OutputStreamWriter ( new FileOutputStream ( file ) , StandardCharsets . UTF_8 ) ) { writer . write ( toString ( ) ) ; } Process gofmt = new ProcessBuilder ( ) . command ( "gofmt" , "-w" , file . getAbsolutePath ( ) ) . inheritIO ( ) . start ( ) ; try { int code = gofmt . waitFor ( ) ; if ( code != 0 ) { throw new IOException ( "Execution of \"gofmt\" on file \"" + file . getAbsolutePath ( ) + "\" failed with exit code " + code ) ; } } catch ( InterruptedException exception ) { throw new IOException ( "Interrupted while waiting for to execute \"gofmt\" on file \"" + file . getAbsolutePath ( ) + "\"" , exception ) ; } }
Creates a {@code .go} source file and writes the source.
Creates a { @code . go } source file and writes the source .
// Calculate the complete file name: // Create the directory and all its parent if needed: // Write the file: // Run the gofmt tool to format the file according to the standard Go rules: