< prev index next >

src/java.base/share/classes/java/io/BufferedInputStream.java

Print this page

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.io;
 27 

 28 import jdk.internal.misc.Unsafe;
 29 import jdk.internal.util.ArraysSupport;
 30 
 31 /**
 32  * A {@code BufferedInputStream} adds
 33  * functionality to another input stream-namely,
 34  * the ability to buffer the input and to
 35  * support the {@code mark} and {@code reset}
 36  * methods. When  the {@code BufferedInputStream}
 37  * is created, an internal buffer array is
 38  * created. As bytes  from the stream are read
 39  * or skipped, the internal buffer is refilled
 40  * as necessary  from the contained input stream,
 41  * many bytes at a time. The {@code mark}
 42  * operation  remembers a point in the input
 43  * stream and the {@code reset} operation
 44  * causes all the  bytes read since the most
 45  * recent {@code mark} operation to be
 46  * reread before new bytes are  taken from
 47  * the contained input stream.
 48  *
 49  * @author  Arthur van Hoff
 50  * @since   1.0
 51  */
 52 public class BufferedInputStream extends FilterInputStream {
 53 
 54     private static int DEFAULT_BUFFER_SIZE = 8192;
 55 
 56     /**
 57      * As this class is used early during bootstrap, it's motivated to use
 58      * Unsafe.compareAndSetObject instead of AtomicReferenceFieldUpdater
 59      * (or VarHandles) to reduce dependencies and improve startup time.
 60      */
 61     private static final Unsafe U = Unsafe.getUnsafe();
 62 
 63     private static final long BUF_OFFSET
 64             = U.objectFieldOffset(BufferedInputStream.class, "buf");
 65 



 66     /**
 67      * The internal buffer array where the data is stored. When necessary,
 68      * it may be replaced by another array of
 69      * a different size.
 70      */
 71     /*
 72      * We null this out with a CAS on close(), which is necessary since
 73      * closes can be asynchronous. We use nullness of buf[] as primary
 74      * indicator that this stream is closed. (The "in" field is also
 75      * nulled out on close.)
 76      */
 77     protected volatile byte[] buf;
 78 
 79     /**
 80      * The index one greater than the index of the last valid byte in
 81      * the buffer.
 82      * This value is always
 83      * in the range {@code 0} through {@code buf.length};
 84      * elements {@code buf[0]} through {@code buf[count-1]}
 85      * contain buffered input data obtained

182     }
183 
184     /**
185      * Creates a {@code BufferedInputStream}
186      * with the specified buffer size,
187      * and saves its  argument, the input stream
188      * {@code in}, for later use.  An internal
189      * buffer array of length  {@code size}
190      * is created and stored in {@code buf}.
191      *
192      * @param   in     the underlying input stream.
193      * @param   size   the buffer size.
194      * @throws  IllegalArgumentException if {@code size <= 0}.
195      */
196     public BufferedInputStream(InputStream in, int size) {
197         super(in);
198         if (size <= 0) {
199             throw new IllegalArgumentException("Buffer size <= 0");
200         }
201         buf = new byte[size];







202     }
203 
204     /**
205      * Fills the buffer with more data, taking into account
206      * shuffling and other tricks for dealing with marks.
207      * Assumes that it is being called by a synchronized method.
208      * This method also assumes that all data has already been read in,
209      * hence pos > count.
210      */
211     private void fill() throws IOException {
212         byte[] buffer = getBufIfOpen();
213         if (markpos < 0)
214             pos = 0;            /* no mark: throw away the buffer */
215         else if (pos >= buffer.length) { /* no room left in buffer */
216             if (markpos > 0) {  /* can throw away early part of the buffer */
217                 int sz = pos - markpos;
218                 System.arraycopy(buffer, markpos, buffer, 0, sz);
219                 pos = sz;
220                 markpos = 0;
221             } else if (buffer.length >= marklimit) {
222                 markpos = -1;   /* buffer got too big, invalidate mark */
223                 pos = 0;        /* drop buffer contents */
224             } else {            /* grow buffer */
225                 int nsz = ArraysSupport.newLength(pos,
226                         1,  /* minimum growth */
227                         pos /* preferred growth */);

241             }
242         }
243         count = pos;
244         int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
245         if (n > 0)
246             count = n + pos;
247     }
248 
249     /**
250      * See
251      * the general contract of the {@code read}
252      * method of {@code InputStream}.
253      *
254      * @return     the next byte of data, or {@code -1} if the end of the
255      *             stream is reached.
256      * @throws     IOException  if this input stream has been closed by
257      *                          invoking its {@link #close()} method,
258      *                          or an I/O error occurs.
259      * @see        java.io.FilterInputStream#in
260      */
261     public synchronized int read() throws IOException {















262         if (pos >= count) {
263             fill();
264             if (pos >= count)
265                 return -1;
266         }
267         return getBufIfOpen()[pos++] & 0xff;
268     }
269 
270     /**
271      * Read characters into a portion of an array, reading from the underlying
272      * stream at most once if necessary.
273      */
274     private int read1(byte[] b, int off, int len) throws IOException {
275         int avail = count - pos;
276         if (avail <= 0) {
277             /* If the requested length is at least as large as the buffer, and
278                if there is no mark/reset activity, do not bother to copy the
279                bytes into the local buffer.  In this way buffered streams will
280                cascade harmlessly. */
281             if (len >= getBufIfOpen().length && markpos < 0) {

311      *   <li> The {@code available} method of the underlying stream
312      *   returns zero, indicating that further input requests would block.
313      *
314      * </ul> If the first {@code read} on the underlying stream returns
315      * {@code -1} to indicate end-of-file then this method returns
316      * {@code -1}.  Otherwise this method returns the number of bytes
317      * actually read.
318      *
319      * <p> Subclasses of this class are encouraged, but not required, to
320      * attempt to read as many bytes as possible in the same fashion.
321      *
322      * @param      b     destination buffer.
323      * @param      off   offset at which to start storing bytes.
324      * @param      len   maximum number of bytes to read.
325      * @return     the number of bytes read, or {@code -1} if the end of
326      *             the stream has been reached.
327      * @throws     IOException  if this input stream has been closed by
328      *                          invoking its {@link #close()} method,
329      *                          or an I/O error occurs.
330      */
331     public synchronized int read(byte[] b, int off, int len)
332         throws IOException
333     {













334         getBufIfOpen(); // Check for closed stream
335         if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
336             throw new IndexOutOfBoundsException();
337         } else if (len == 0) {
338             return 0;
339         }
340 
341         int n = 0;
342         for (;;) {
343             int nread = read1(b, off + n, len - n);
344             if (nread <= 0)
345                 return (n == 0) ? nread : n;
346             n += nread;
347             if (n >= len)
348                 return n;
349             // if not closed but no bytes available, return
350             InputStream input = in;
351             if (input != null && input.available() <= 0)
352                 return n;
353         }
354     }
355 
356     /**
357      * See the general contract of the {@code skip}
358      * method of {@code InputStream}.
359      *
360      * @throws IOException  if this input stream has been closed by
361      *                      invoking its {@link #close()} method,
362      *                      {@code in.skip(n)} throws an IOException,
363      *                      or an I/O error occurs.
364      */
365     public synchronized long skip(long n) throws IOException {















366         getBufIfOpen(); // Check for closed stream
367         if (n <= 0) {
368             return 0;
369         }
370         long avail = count - pos;
371 
372         if (avail <= 0) {
373             // If no mark position set then don't keep in buffer
374             if (markpos <0)
375                 return getInIfOpen().skip(n);
376 
377             // Fill in buffer to save bytes for reset
378             fill();
379             avail = count - pos;
380             if (avail <= 0)
381                 return 0;
382         }
383 
384         long skipped = (avail < n) ? avail : n;
385         pos += skipped;
386         return skipped;
387     }
388 
389     /**
390      * Returns an estimate of the number of bytes that can be read (or
391      * skipped over) from this input stream without blocking by the next
392      * invocation of a method for this input stream. The next invocation might be
393      * the same thread or another thread.  A single read or skip of this
394      * many bytes will not block, but may read or skip fewer bytes.
395      * <p>
396      * This method returns the sum of the number of bytes remaining to be read in
397      * the buffer ({@code count - pos}) and the result of calling the
398      * {@link java.io.FilterInputStream#in in}{@code .available()}.
399      *
400      * @return     an estimate of the number of bytes that can be read (or skipped
401      *             over) from this input stream without blocking.
402      * @throws     IOException  if this input stream has been closed by
403      *                          invoking its {@link #close()} method,
404      *                          or an I/O error occurs.
405      */
406     public synchronized int available() throws IOException {















407         int n = count - pos;
408         int avail = getInIfOpen().available();
409         return n > (Integer.MAX_VALUE - avail)
410                     ? Integer.MAX_VALUE
411                     : n + avail;
412     }
413 
414     /**
415      * See the general contract of the {@code mark}
416      * method of {@code InputStream}.
417      *
418      * @param   readlimit   the maximum limit of bytes that can be read before
419      *                      the mark position becomes invalid.
420      * @see     java.io.BufferedInputStream#reset()
421      */
422     public synchronized void mark(int readlimit) {















423         marklimit = readlimit;
424         markpos = pos;
425     }
426 
427     /**
428      * See the general contract of the {@code reset}
429      * method of {@code InputStream}.
430      * <p>
431      * If {@code markpos} is {@code -1}
432      * (no mark has been set or the mark has been
433      * invalidated), an {@code IOException}
434      * is thrown. Otherwise, {@code pos} is
435      * set equal to {@code markpos}.
436      *
437      * @throws     IOException  if this stream has not been marked or,
438      *                  if the mark has been invalidated, or the stream
439      *                  has been closed by invoking its {@link #close()}
440      *                  method, or an I/O error occurs.
441      * @see        java.io.BufferedInputStream#mark(int)
442      */
443     public synchronized void reset() throws IOException {















444         getBufIfOpen(); // Cause exception if closed
445         if (markpos < 0)
446             throw new IOException("Resetting to invalid mark");
447         pos = markpos;
448     }
449 
450     /**
451      * Tests if this input stream supports the {@code mark}
452      * and {@code reset} methods. The {@code markSupported}
453      * method of {@code BufferedInputStream} returns
454      * {@code true}.
455      *
456      * @return  a {@code boolean} indicating if this stream type supports
457      *          the {@code mark} and {@code reset} methods.
458      * @see     java.io.InputStream#mark(int)
459      * @see     java.io.InputStream#reset()
460      */
461     public boolean markSupported() {
462         return true;
463     }

  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package java.io;
 27 
 28 import jdk.internal.misc.InternalLock;
 29 import jdk.internal.misc.Unsafe;
 30 import jdk.internal.util.ArraysSupport;
 31 
 32 /**
 33  * A {@code BufferedInputStream} adds
 34  * functionality to another input stream-namely,
 35  * the ability to buffer the input and to
 36  * support the {@code mark} and {@code reset}
 37  * methods. When  the {@code BufferedInputStream}
 38  * is created, an internal buffer array is
 39  * created. As bytes  from the stream are read
 40  * or skipped, the internal buffer is refilled
 41  * as necessary  from the contained input stream,
 42  * many bytes at a time. The {@code mark}
 43  * operation  remembers a point in the input
 44  * stream and the {@code reset} operation
 45  * causes all the  bytes read since the most
 46  * recent {@code mark} operation to be
 47  * reread before new bytes are  taken from
 48  * the contained input stream.
 49  *
 50  * @author  Arthur van Hoff
 51  * @since   1.0
 52  */
 53 public class BufferedInputStream extends FilterInputStream {
 54 
 55     private static int DEFAULT_BUFFER_SIZE = 8192;
 56 
 57     /**
 58      * As this class is used early during bootstrap, it's motivated to use
 59      * Unsafe.compareAndSetObject instead of AtomicReferenceFieldUpdater
 60      * (or VarHandles) to reduce dependencies and improve startup time.
 61      */
 62     private static final Unsafe U = Unsafe.getUnsafe();
 63 
 64     private static final long BUF_OFFSET
 65             = U.objectFieldOffset(BufferedInputStream.class, "buf");
 66 
 67     // initialized to null when BufferedInputStream is sub-classed
 68     private final InternalLock lock;
 69 
 70     /**
 71      * The internal buffer array where the data is stored. When necessary,
 72      * it may be replaced by another array of
 73      * a different size.
 74      */
 75     /*
 76      * We null this out with a CAS on close(), which is necessary since
 77      * closes can be asynchronous. We use nullness of buf[] as primary
 78      * indicator that this stream is closed. (The "in" field is also
 79      * nulled out on close.)
 80      */
 81     protected volatile byte[] buf;
 82 
 83     /**
 84      * The index one greater than the index of the last valid byte in
 85      * the buffer.
 86      * This value is always
 87      * in the range {@code 0} through {@code buf.length};
 88      * elements {@code buf[0]} through {@code buf[count-1]}
 89      * contain buffered input data obtained

186     }
187 
188     /**
189      * Creates a {@code BufferedInputStream}
190      * with the specified buffer size,
191      * and saves its  argument, the input stream
192      * {@code in}, for later use.  An internal
193      * buffer array of length  {@code size}
194      * is created and stored in {@code buf}.
195      *
196      * @param   in     the underlying input stream.
197      * @param   size   the buffer size.
198      * @throws  IllegalArgumentException if {@code size <= 0}.
199      */
200     public BufferedInputStream(InputStream in, int size) {
201         super(in);
202         if (size <= 0) {
203             throw new IllegalArgumentException("Buffer size <= 0");
204         }
205         buf = new byte[size];
206 
207         // use monitors when BufferedInputStream is sub-classed
208         if (getClass() == BufferedInputStream.class) {
209             lock = new InternalLock();
210         } else {
211             lock = null;
212         }
213     }
214 
215     /**
216      * Fills the buffer with more data, taking into account
217      * shuffling and other tricks for dealing with marks.
218      * Assumes that it is being called by a locked method.
219      * This method also assumes that all data has already been read in,
220      * hence pos > count.
221      */
222     private void fill() throws IOException {
223         byte[] buffer = getBufIfOpen();
224         if (markpos < 0)
225             pos = 0;            /* no mark: throw away the buffer */
226         else if (pos >= buffer.length) { /* no room left in buffer */
227             if (markpos > 0) {  /* can throw away early part of the buffer */
228                 int sz = pos - markpos;
229                 System.arraycopy(buffer, markpos, buffer, 0, sz);
230                 pos = sz;
231                 markpos = 0;
232             } else if (buffer.length >= marklimit) {
233                 markpos = -1;   /* buffer got too big, invalidate mark */
234                 pos = 0;        /* drop buffer contents */
235             } else {            /* grow buffer */
236                 int nsz = ArraysSupport.newLength(pos,
237                         1,  /* minimum growth */
238                         pos /* preferred growth */);

252             }
253         }
254         count = pos;
255         int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
256         if (n > 0)
257             count = n + pos;
258     }
259 
260     /**
261      * See
262      * the general contract of the {@code read}
263      * method of {@code InputStream}.
264      *
265      * @return     the next byte of data, or {@code -1} if the end of the
266      *             stream is reached.
267      * @throws     IOException  if this input stream has been closed by
268      *                          invoking its {@link #close()} method,
269      *                          or an I/O error occurs.
270      * @see        java.io.FilterInputStream#in
271      */
272     public int read() throws IOException {
273         if (lock != null) {
274             lock.lock();
275             try {
276                 return lockedRead();
277             } finally {
278                 lock.unlock();
279             }
280         } else {
281             synchronized (this) {
282                 return lockedRead();
283             }
284         }
285     }
286 
287     private int lockedRead() throws IOException {
288         if (pos >= count) {
289             fill();
290             if (pos >= count)
291                 return -1;
292         }
293         return getBufIfOpen()[pos++] & 0xff;
294     }
295 
296     /**
297      * Read characters into a portion of an array, reading from the underlying
298      * stream at most once if necessary.
299      */
300     private int read1(byte[] b, int off, int len) throws IOException {
301         int avail = count - pos;
302         if (avail <= 0) {
303             /* If the requested length is at least as large as the buffer, and
304                if there is no mark/reset activity, do not bother to copy the
305                bytes into the local buffer.  In this way buffered streams will
306                cascade harmlessly. */
307             if (len >= getBufIfOpen().length && markpos < 0) {

337      *   <li> The {@code available} method of the underlying stream
338      *   returns zero, indicating that further input requests would block.
339      *
340      * </ul> If the first {@code read} on the underlying stream returns
341      * {@code -1} to indicate end-of-file then this method returns
342      * {@code -1}.  Otherwise this method returns the number of bytes
343      * actually read.
344      *
345      * <p> Subclasses of this class are encouraged, but not required, to
346      * attempt to read as many bytes as possible in the same fashion.
347      *
348      * @param      b     destination buffer.
349      * @param      off   offset at which to start storing bytes.
350      * @param      len   maximum number of bytes to read.
351      * @return     the number of bytes read, or {@code -1} if the end of
352      *             the stream has been reached.
353      * @throws     IOException  if this input stream has been closed by
354      *                          invoking its {@link #close()} method,
355      *                          or an I/O error occurs.
356      */
357     public int read(byte[] b, int off, int len) throws IOException {
358         if (lock != null) {
359             lock.lock();
360             try {
361                 return lockedRead(b, off, len);
362             } finally {
363                 lock.unlock();
364             }
365         } else {
366             synchronized (this) {
367                 return lockedRead(b, off, len);
368             }
369         }
370     }
371 
372     private int lockedRead(byte[] b, int off, int len) throws IOException {
373         getBufIfOpen(); // Check for closed stream
374         if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
375             throw new IndexOutOfBoundsException();
376         } else if (len == 0) {
377             return 0;
378         }
379 
380         int n = 0;
381         for (;;) {
382             int nread = read1(b, off + n, len - n);
383             if (nread <= 0)
384                 return (n == 0) ? nread : n;
385             n += nread;
386             if (n >= len)
387                 return n;
388             // if not closed but no bytes available, return
389             InputStream input = in;
390             if (input != null && input.available() <= 0)
391                 return n;
392         }
393     }
394 
395     /**
396      * See the general contract of the {@code skip}
397      * method of {@code InputStream}.
398      *
399      * @throws IOException  if this input stream has been closed by
400      *                      invoking its {@link #close()} method,
401      *                      {@code in.skip(n)} throws an IOException,
402      *                      or an I/O error occurs.
403      */
404     public long skip(long n) throws IOException {
405         if (lock != null) {
406             lock.lock();
407             try {
408                 return lockedSkip(n);
409             } finally {
410                 lock.unlock();
411             }
412         } else {
413             synchronized (this) {
414                 return lockedSkip(n);
415             }
416         }
417     }
418 
419     private long lockedSkip(long n) throws IOException {
420         getBufIfOpen(); // Check for closed stream
421         if (n <= 0) {
422             return 0;
423         }
424         long avail = count - pos;
425 
426         if (avail <= 0) {
427             // If no mark position set then don't keep in buffer
428             if (markpos <0)
429                 return getInIfOpen().skip(n);
430 
431             // Fill in buffer to save bytes for reset
432             fill();
433             avail = count - pos;
434             if (avail <= 0)
435                 return 0;
436         }
437 
438         long skipped = (avail < n) ? avail : n;
439         pos += skipped;
440         return skipped;
441     }
442 
443     /**
444      * Returns an estimate of the number of bytes that can be read (or
445      * skipped over) from this input stream without blocking by the next
446      * invocation of a method for this input stream. The next invocation might be
447      * the same thread or another thread.  A single read or skip of this
448      * many bytes will not block, but may read or skip fewer bytes.
449      * <p>
450      * This method returns the sum of the number of bytes remaining to be read in
451      * the buffer ({@code count - pos}) and the result of calling the
452      * {@link java.io.FilterInputStream#in in}{@code .available()}.
453      *
454      * @return     an estimate of the number of bytes that can be read (or skipped
455      *             over) from this input stream without blocking.
456      * @throws     IOException  if this input stream has been closed by
457      *                          invoking its {@link #close()} method,
458      *                          or an I/O error occurs.
459      */
460     public int available() throws IOException {
461         if (lock != null) {
462             lock.lock();
463             try {
464                 return lockAvailable();
465             } finally {
466                 lock.unlock();
467             }
468         } else {
469             synchronized (this) {
470                 return lockAvailable();
471             }
472         }
473     }
474 
475     private int lockAvailable() throws IOException {
476         int n = count - pos;
477         int avail = getInIfOpen().available();
478         return n > (Integer.MAX_VALUE - avail)
479                     ? Integer.MAX_VALUE
480                     : n + avail;
481     }
482 
483     /**
484      * See the general contract of the {@code mark}
485      * method of {@code InputStream}.
486      *
487      * @param   readlimit   the maximum limit of bytes that can be read before
488      *                      the mark position becomes invalid.
489      * @see     java.io.BufferedInputStream#reset()
490      */
491     public void mark(int readlimit) {
492         if (lock != null) {
493             lock.lock();
494             try {
495                 lockedMark(readlimit);
496             } finally {
497                 lock.unlock();
498             }
499         } else {
500             synchronized (this) {
501                 lockedMark(readlimit);
502             }
503         }
504     }
505 
506     private void lockedMark(int readlimit) {
507         marklimit = readlimit;
508         markpos = pos;
509     }
510 
511     /**
512      * See the general contract of the {@code reset}
513      * method of {@code InputStream}.
514      * <p>
515      * If {@code markpos} is {@code -1}
516      * (no mark has been set or the mark has been
517      * invalidated), an {@code IOException}
518      * is thrown. Otherwise, {@code pos} is
519      * set equal to {@code markpos}.
520      *
521      * @throws     IOException  if this stream has not been marked or,
522      *                  if the mark has been invalidated, or the stream
523      *                  has been closed by invoking its {@link #close()}
524      *                  method, or an I/O error occurs.
525      * @see        java.io.BufferedInputStream#mark(int)
526      */
527     public void reset() throws IOException {
528         if (lock != null) {
529             lock.lock();
530             try {
531                 lockedReset();
532             } finally {
533                 lock.unlock();
534             }
535         } else {
536             synchronized (this) {
537                 lockedReset();
538             }
539         }
540     }
541 
542     private void lockedReset() throws IOException {
543         getBufIfOpen(); // Cause exception if closed
544         if (markpos < 0)
545             throw new IOException("Resetting to invalid mark");
546         pos = markpos;
547     }
548 
549     /**
550      * Tests if this input stream supports the {@code mark}
551      * and {@code reset} methods. The {@code markSupported}
552      * method of {@code BufferedInputStream} returns
553      * {@code true}.
554      *
555      * @return  a {@code boolean} indicating if this stream type supports
556      *          the {@code mark} and {@code reset} methods.
557      * @see     java.io.InputStream#mark(int)
558      * @see     java.io.InputStream#reset()
559      */
560     public boolean markSupported() {
561         return true;
562     }
< prev index next >