All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.thinkerou.karate.message.Output Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.github.thinkerou.karate.message;

import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.nio.file.Path;

/**
 * Output
 *
 * @author thinkerou
 */
public class Output implements AutoCloseable {

    private final PrintStream printStream;

    Output(PrintStream printStream) {
        this.printStream = printStream;
    }

    public void write(String content) {
        printStream.print(content);
    }

    public void writeLine(String content) {
        printStream.println(content);
    }

    public void newLine() {
        printStream.println();
    }

    public static Output forFile(Path path) {
        try {
            return new Output(new PrintStream(path.toString()));
        } catch (FileNotFoundException e) {
            throw new IllegalArgumentException("Can't create writer for file: " + path, e);
        }
    }

    public static Output forStream(PrintStream printStream) {
        return new Output(printStream);
    }

    @Override
    public void close() {
        printStream.close();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy