Package org.apache.commons.io.input
Class CircularInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.CircularInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
InfiniteCircularInputStream
An
InputStream
that repeats provided bytes for given target byte count.
Closing this input stream has no effect. The methods in this class can be called after the stream has been closed
without generating an IOException
.
- Since:
- 2.8.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
private int
private final byte[]
private final long
-
Constructor Summary
ConstructorsConstructorDescriptionCircularInputStream
(byte[] repeatContent, long targetByteCount) Creates an instance from the specified array of bytes. -
Method Summary
Modifier and TypeMethodDescriptionint
read()
private static byte[]
validate
(byte[] repeatContent) Throws anIllegalArgumentException
if the input contains -1.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
-
Field Details
-
byteCount
private long byteCount -
position
private int position -
repeatedContent
private final byte[] repeatedContent -
targetByteCount
private final long targetByteCount
-
-
Constructor Details
-
CircularInputStream
public CircularInputStream(byte[] repeatContent, long targetByteCount) Creates an instance from the specified array of bytes.- Parameters:
repeatContent
- Input buffer to be repeated this buffer is not copied.targetByteCount
- How many bytes the read. A negative number means an infinite target count.
-
-
Method Details
-
validate
private static byte[] validate(byte[] repeatContent) Throws anIllegalArgumentException
if the input contains -1.- Parameters:
repeatContent
- input to validate.- Returns:
- the input.
-
read
public int read()- Specified by:
read
in classInputStream
-