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());
}
}
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());
}
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;
}
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());
}
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;
}
Aggregations