public class CircleInputStream extends InputStream
For special needs, not thread-safe, use with care, especially use mark, reset properly. Uses byte[] to cache the read stream, and if read again after the stream is read out, i.e. -1, the read will auto start from the beginning of the cache (re-available) Optimized only for ByteArrayInputStream and FileInputStream constructed from files. Other Streams, will cache all read content, need to pay attention to memory consumption.
NonCloseStream| Modifier and Type | Field and Description |
|---|---|
protected @NotNull InputStream |
backend |
protected ByteArrayOutputStream |
caching |
protected byte[] |
content |
protected File |
file |
protected int |
length |
protected int |
offset |
| Constructor and Description |
|---|
CircleInputStream(byte[] cache) |
CircleInputStream(byte[] cache,
int offset,
int length) |
CircleInputStream(@NotNull ByteArrayOutputStream cache) |
CircleInputStream(@NotNull File file) |
CircleInputStream(@NotNull InputStream backend) |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
byte[] |
getContent() |
File |
getFile() |
boolean |
isFinished()
Whether read out the stream (-1) at this time.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
@NotNull protected @NotNull InputStream backend
protected ByteArrayOutputStream caching
protected File file
protected byte[] content
protected int offset
protected int length
public CircleInputStream(@NotNull
@NotNull InputStream backend)
public CircleInputStream(@NotNull
@NotNull File file)
public CircleInputStream(@NotNull
@NotNull ByteArrayOutputStream cache)
public CircleInputStream(byte[] cache)
public CircleInputStream(byte[] cache,
int offset,
int length)
public boolean isFinished()
public int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b)
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class InputStreamIOExceptionpublic int available()
throws IOException
available in class InputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic void mark(int readlimit)
mark in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOExceptionpublic boolean markSupported()
markSupported in class InputStreampublic byte[] getContent()
public File getFile()
Copyright © 2023. All rights reserved.