de.schlichtherle.truezip.io.DecoratingInputStream Maven / Gradle / Ivy
/*
* Copyright (C) 2005-2015 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package de.schlichtherle.truezip.io;
import edu.umd.cs.findbugs.annotations.CleanupObligation;
import edu.umd.cs.findbugs.annotations.CreatesObligation;
import edu.umd.cs.findbugs.annotations.DischargesObligation;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Nullable;
import javax.annotation.WillCloseWhenClosed;
/**
* An abstract decorator for an input stream.
* This is a clean room implementation of its cousin {@link FilterInputStream}
* in the JSE, but optimized for performance and without
* multithreading support.
*
* @see DecoratingOutputStream
* @author Christian Schlichtherle
*/
@CleanupObligation
public abstract class DecoratingInputStream extends InputStream {
/** The nullable decorated input stream. */
protected @Nullable InputStream delegate;
/**
* Constructs a new decorating input stream.
*
* @param delegate the nullable input stream to decorate.
*/
@CreatesObligation
protected DecoratingInputStream(
final @Nullable @WillCloseWhenClosed InputStream delegate) {
this.delegate = delegate;
}
@Override
public int read() throws IOException {
return delegate.read();
}
@Override
public final int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
return delegate.read(b, off, len);
}
@Override
public long skip(long n) throws IOException {
return delegate.skip(n);
}
@Override
public int available() throws IOException {
return delegate.available();
}
@Override
@DischargesObligation
public void close() throws IOException {
delegate.close();
}
@Override
public void mark(int readlimit) {
delegate.mark(readlimit);
}
@Override
public void reset() throws IOException {
delegate.reset();
}
@Override
public boolean markSupported() {
return delegate.markSupported();
}
/**
* Returns a string representation of this object for debugging and logging
* purposes.
*/
@Override
public String toString() {
return String.format("%s[delegate=%s]",
getClass().getName(),
delegate);
}
}