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

io.fabric8.maven.docker.log.SharedPrintStream Maven / Gradle / Ivy

There is a newer version: 0.45.0
Show newest version
package io.fabric8.maven.docker.log;

import java.io.PrintStream;
import java.util.concurrent.atomic.AtomicInteger;

class SharedPrintStream {
    private PrintStream printStream;

    private AtomicInteger numUsers;

    SharedPrintStream(PrintStream ps) {
        this.printStream = ps;
        this.numUsers = new AtomicInteger(1);
    }

    PrintStream getPrintStream() {
        return printStream;
    }

    void allocate() {
        numUsers.incrementAndGet();
    }

    boolean close() {
        int nrUsers = numUsers.decrementAndGet();
        if (nrUsers == 0 && printStream != System.out) {
            printStream.close();
            return true;
        } else {
            return false;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy