A specialized InputStream for reading the contents of a byte array. @see ByteArrayOutputStream
| 23 | * @see ByteArrayOutputStream |
| 24 | */ |
| 25 | public class ByteArrayInputStream extends InputStream { |
| 26 | /** |
| 27 | * The {@code byte} array containing the bytes to stream over. |
| 28 | */ |
| 29 | protected byte[] buf; |
| 30 | |
| 31 | /** |
| 32 | * The current position within the byte array. |
| 33 | */ |
| 34 | protected int pos; |
| 35 | |
| 36 | /** |
| 37 | * The current mark position. Initially set to 0 or the <code>offset</code> |
| 38 | * parameter within the constructor. |
| 39 | */ |
| 40 | protected int mark; |
| 41 | |
| 42 | /** |
| 43 | * The total number of bytes initially available in the byte array |
| 44 | * {@code buf}. |
| 45 | */ |
| 46 | protected int count; |
| 47 | |
| 48 | /** |
| 49 | * Constructs a new {@code ByteArrayInputStream} on the byte array |
| 50 | * {@code buf}. |
| 51 | * |
| 52 | * @param buf |
| 53 | * the byte array to stream over. |
| 54 | */ |
| 55 | public ByteArrayInputStream(byte buf[]) { |
| 56 | this.mark = 0; |
| 57 | this.buf = buf; |
| 58 | this.count = buf.length; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Constructs a new {@code ByteArrayInputStream} on the byte array |
| 63 | * {@code buf} with the initial position set to {@code offset} and the |
| 64 | * number of bytes available set to {@code offset} + {@code length}. |
| 65 | * |
| 66 | * @param buf |
| 67 | * the byte array to stream over. |
| 68 | * @param offset |
| 69 | * the initial position in {@code buf} to start streaming from. |
| 70 | * @param length |
| 71 | * the number of bytes available for streaming. |
| 72 | */ |
| 73 | public ByteArrayInputStream(byte buf[], int offset, int length) { |
| 74 | this.buf = buf; |
| 75 | pos = offset; |
| 76 | mark = offset; |
| 77 | count = offset + length > buf.length ? buf.length : offset + length; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the number of bytes that are available before this stream will |
| 82 | * block. This method returns the number of bytes yet to be read from the |
nothing calls this directly
no outgoing calls
no test coverage detected