public final class ExceptionPassthroughInputStream
extends java.io.InputStream
InputStream that catches, stores and rethrows IOExceptions
during read and skip calls. This allows users of this API to handle the exception at a higher
level if the exception is swallowed by some intermediate library. This class is a workaround for
a framework issue where exceptions during reads while decoding bitmaps in BitmapFactory can return partially decoded bitmaps.
Unlike the deprecated ExceptionCatchingInputStream, this class will both store and
re-throw any IOExceptions. Rethrowing works around bugs in wrapping streams that may not fully
obey the stream contract. This is really only useful if some middle layer is going to catch the
exception (like BitmapFactory) but we want to propagate the exception instead.
See https://github.com/bumptech/glide/issues/126 and #4438.
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
java.io.IOException |
getException() |
void |
mark(int readLimit) |
boolean |
markSupported() |
static ExceptionPassthroughInputStream |
obtain(java.io.InputStream toWrap) |
int |
read() |
int |
read(byte[] buffer) |
int |
read(byte[] buffer,
int byteOffset,
int byteCount) |
void |
release() |
void |
reset() |
long |
skip(long byteCount) |
@NonNull public static ExceptionPassthroughInputStream obtain(@NonNull java.io.InputStream toWrap)
public int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic void mark(int readLimit)
mark in class java.io.InputStreampublic boolean markSupported()
markSupported in class java.io.InputStreampublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] buffer)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] buffer,
int byteOffset,
int byteCount)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic void reset()
throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic long skip(long byteCount)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOException@Nullable public java.io.IOException getException()
public void release()