use of org.cactoos.text.UncheckedText in project cactoos by yegor256.
the class LoggingInputStream method reset.
@Override
public void reset() throws IOException {
this.origin.reset();
this.logger.log(this.level.value(), new UncheckedText(new FormattedText("Reset input stream from %s.", this.source)).asString());
}
use of org.cactoos.text.UncheckedText in project cactoos by yegor256.
the class LoggingOutputStream method flush.
@Override
public void flush() throws IOException {
this.origin.flush();
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("Flushed output stream from %s.", this.destination)).asString());
}
use of org.cactoos.text.UncheckedText in project cactoos by yegor256.
the class Checked method wrappedException.
/**
* Wraps exception.
* Skips unnecessary wrapping of exceptions of the same type.
* Allows wrapping of exceptions of the same type if the error message
* has been changed.
*
* @param exp Exception
* @return E Wrapped exception
*/
@SuppressWarnings("unchecked")
private E wrappedException(final Exception exp) {
E wrapped = new UncheckedFunc<>(this.func).apply(exp);
final int level = new InheritanceLevel(exp.getClass(), wrapped.getClass()).value();
final String message = wrapped.getMessage().replaceFirst(new UncheckedText(new FormattedText("%s: ", exp.getClass().getName())).asString(), "");
if (level >= 0 && message.equals(exp.getMessage())) {
wrapped = (E) exp;
}
return wrapped;
}
use of org.cactoos.text.UncheckedText in project cactoos by yegor256.
the class NoNulls method next.
@Override
public X next() {
final X next = this.iterator.next();
if (next == null) {
throw new IllegalStateException(new UncheckedText(new FormattedText("Item #%d of %s is NULL", this.pos.get(), this.iterator)).asString());
}
this.pos.incrementAndGet();
return next;
}
use of org.cactoos.text.UncheckedText in project cactoos by yegor256.
the class LoggingInputStream method read.
@Override
public int read(final byte[] buf, final int offset, final int len) throws IOException {
final Instant start = Instant.now();
final int byts = this.origin.read(buf, offset, len);
final Instant end = Instant.now();
final long millis = Duration.between(start, end).toMillis();
if (byts > 0) {
this.bytes.getAndAdd(byts);
this.time.getAndAdd(millis);
}
final UncheckedText msg = new UncheckedText(new FormattedText("Read %d byte(s) from %s in %dms.", this.bytes.get(), this.source, this.time.get()));
if (byts > 0) {
if (!this.level.value().equals(Level.INFO)) {
this.logger.log(this.level.value(), msg.asString());
}
} else {
if (this.level.value().equals(Level.INFO)) {
this.logger.info(msg.asString());
}
}
return byts;
}
Aggregations