Lines Matching defs:index

32  * say you have a loop that reads bytes from index <code>0</code> to <code>10</code>,
33 * skips to index <code>N</code>, reads from index <code>N</code> to <code>N+10</code>, etc. Then
39 * helps to keep the internal buffer small. In the above example, after reading bytes from index
41 * buffer becomes filled with bytes from index <code>N</code> to <code>N+10</code>.
45 * index, then you should set the <code>autoAdvance</code> parameter to <code>true</code> in the
48 * <code>autoAdvance</code> is enabled, every time an index is beyond the buffer length,
49 * the buffer will be shifted forward such that the index requested becomes the first element in
53 * All public methods with parameter <code>index</code> are absolute indexed. The index is from
75 * or {@link #has(int)} with an index N, then some arbitrary time later call {@link #get(int)}
76 * or {@link #has(int)} with an index M < N. The wrapper may return the right value,
77 * if the buffer happens to still contain index M, but more likely it will throw an
91 * @param autoAdvance Determines the behavior when you need to read an index that is beyond
93 * that the requested index becomes the first element. If false,
95 * greater than the requested index.
110 * Attempt to get byte at the requested index from the wrapped input stream. If the internal
111 * buffer contains the requested index, return immediately. If the index is less than the
112 * head of the buffer, or the index is greater or equal to the size of the wrapped input stream,
116 * If the index is not in the internal buffer, but it can be requested from the input stream,
117 * {@link #fill(int)} will be called first, and the byte at the index returned.
120 * You should always call {@link #has(int)} with the same index, unless you are sure that no
125 * index in the future.
126 * @param index The requested index.
127 * @return The byte at that index.
129 public byte get(final int index) throws IllegalStateException, IndexOutOfBoundsException {
131 if (has(index)) {
132 final int i = index - mOffset;
138 String.format("Index %d beyond length.", index));
143 * Attempt to return whether the requested index is within the size of the wrapped input
147 * If this method returns true, it is guaranteed that {@link #get(int)} with the same index
148 * will not fail. That means that if the requested index is within the size of the wrapped
149 * input stream, but the index is less than the head of the internal buffer,
155 * @param index The requested index.
156 * @return True if requested index is within the size of the wrapped input stream. False if
157 * the index is beyond the size.
159 public boolean has(final int index) throws IllegalStateException, IndexOutOfBoundsException {
161 if (index < mOffset) {
164 String.format("Index %d is before buffer %d", index, mOffset));
167 final int i = index - mOffset;
169 // Requested index not in internal buffer.
172 return fill(index);
180 * Attempts to advance the head of the buffer to the requested index. If the index is less
187 public void advanceTo(final int index) throws IllegalStateException, IndexOutOfBoundsException {
189 final int i = index - mOffset;
197 mOffset = index;
200 // Burn some bytes from the input stream to match the new index.
227 mOffset = index - burn;
231 mOffset = index;
243 * requested index will always be in the buffer. If the index is less
247 * If the requested index is already in bounds of the buffer, then the buffer will just be
252 * {@link #advanceTo(int)} will be called with the requested index,
255 * requested index. The elements in the old buffer are copied over to the head of the new
257 * @param index The requested index.
258 * @return True if the byte at the requested index has been filled. False if the wrapped
259 * input stream ends before we reach the index.
261 private boolean fill(final int index) {
263 if (index < mOffset) {
266 String.format("Index %d is before buffer %d", index, mOffset));
269 int i = index - mOffset;
280 advanceTo(index);
281 i = index - mOffset;
316 * <code>i</code>. In other words, the byte at index <code>i</code> will now be at index
317 * <code>0</code>. Bytes from a lesser index are tossed.