Package io.mochaapi.client
Class ManagedInputStream
java.lang.Object
java.io.InputStream
io.mochaapi.client.ManagedInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A managed InputStream wrapper that implements AutoCloseable for proper resource management.
This class ensures that streams are properly closed and helps prevent memory leaks.
Usage example:
try (ManagedInputStream stream = apiRequest.downloadStream()) {
// Use the stream
byte[] data = stream.readAllBytes();
} // Stream is automatically closed
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionManagedInputStream(byte[] data) Creates a new ManagedInputStream wrapping the provided byte array. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()booleanisClosed()Returns true if this stream has been closed.voidmark(int readlimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()intsize()Returns the number of bytes that can be read from this stream.longskip(long n) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ManagedInputStream
public ManagedInputStream(byte[] data) Creates a new ManagedInputStream wrapping the provided byte array.- Parameters:
data- the byte array to wrap- Throws:
IllegalArgumentException- if data is null
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
size
public int size()Returns the number of bytes that can be read from this stream.- Returns:
- the number of bytes available
-
isClosed
public boolean isClosed()Returns true if this stream has been closed.- Returns:
- true if closed, false otherwise
-