Search in sources :

Example 6 with UncheckedText

use of org.cactoos.text.UncheckedText in project cactoos by yegor256.

the class LoggingOutputStream method write.

@Override
public void write(final byte[] buf, final int offset, final int len) throws IOException {
    final Instant start = Instant.now();
    this.origin.write(buf, offset, len);
    final Instant end = Instant.now();
    final long millis = Duration.between(start, end).toMillis();
    this.bytes.getAndAdd(len);
    this.time.getAndAdd(millis);
    final Level level = this.logger.getLevel();
    if (!level.equals(Level.INFO)) {
        this.logger.log(level, new UncheckedText(new FormattedText("Written %d byte(s) to %s in %dms.", this.bytes.get(), this.destination, this.time.get())).asString());
    }
}
Also used : UncheckedText(org.cactoos.text.UncheckedText) Instant(java.time.Instant) Level(java.util.logging.Level) FormattedText(org.cactoos.text.FormattedText)

Example 7 with UncheckedText

use of org.cactoos.text.UncheckedText in project cactoos by yegor256.

the class LoggingOutputStream method close.

@Override
public void close() throws IOException {
    this.origin.close();
    final Level level = this.logger.getLevel();
    if (level.equals(Level.INFO)) {
        this.logger.log(level, new UncheckedText(new FormattedText("Written %d byte(s) to %s in %dms.", this.bytes.get(), this.destination, this.time.get())).asString());
    }
    this.logger.log(level, new UncheckedText(new FormattedText("Closed output stream from %s.", this.destination)).asString());
}
Also used : UncheckedText(org.cactoos.text.UncheckedText) Level(java.util.logging.Level) FormattedText(org.cactoos.text.FormattedText)

Example 8 with UncheckedText

use of org.cactoos.text.UncheckedText in project cactoos by yegor256.

the class LoggingInputStream method available.

@Override
public int available() throws IOException {
    final int avail = this.origin.available();
    this.logger.log(this.level.value(), new UncheckedText(new FormattedText("There is(are) %d byte(s) available from %s.", avail, this.source)).asString());
    return avail;
}
Also used : UncheckedText(org.cactoos.text.UncheckedText) FormattedText(org.cactoos.text.FormattedText)

Example 9 with UncheckedText

use of org.cactoos.text.UncheckedText in project cactoos by yegor256.

the class LoggingInputStream method close.

@Override
public void close() throws IOException {
    this.origin.close();
    this.logger.log(this.level.value(), new UncheckedText(new FormattedText("Closed input stream from %s.", this.source)).asString());
}
Also used : UncheckedText(org.cactoos.text.UncheckedText) FormattedText(org.cactoos.text.FormattedText)

Example 10 with UncheckedText

use of org.cactoos.text.UncheckedText in project cactoos by yegor256.

the class LoggingInputStream method markSupported.

@Override
public boolean markSupported() {
    final boolean supported = this.origin.markSupported();
    final String msg;
    if (supported) {
        msg = "Mark and reset are supported from %s";
    } else {
        msg = "Mark and reset NOT supported from %s";
    }
    this.logger.log(this.level.value(), new UncheckedText(new FormattedText(msg, this.source)).asString());
    return supported;
}
Also used : UncheckedText(org.cactoos.text.UncheckedText) FormattedText(org.cactoos.text.FormattedText)

Aggregations

UncheckedText (org.cactoos.text.UncheckedText)13 FormattedText (org.cactoos.text.FormattedText)12 Level (java.util.logging.Level)3 Instant (java.time.Instant)2 TextOf (org.cactoos.text.TextOf)1 IsIterableContainingInOrder (org.hamcrest.collection.IsIterableContainingInOrder)1 Test (org.junit.jupiter.api.Test)1 IsText (org.llorllale.cactoos.matchers.IsText)1