MCPcopy Create free account
hub / github.com/davidgiven/luje / ByteArrayInputStream

Class ByteArrayInputStream

lib/java/io/ByteArrayInputStream.java:25–220  ·  view source on GitHub ↗

A specialized InputStream for reading the contents of a byte array. @see ByteArrayOutputStream

Source from the content-addressed store, hash-verified

23 * @see ByteArrayOutputStream
24 */
25public 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected