Home | History | Annotate | Download | only in io
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package libcore.io;
     18 
     19 /**
     20  * Iterates over big- or little-endian bytes. See {@link MemoryMappedFile#bigEndianIterator} and
     21  * {@link MemoryMappedFile#littleEndianIterator}.
     22  *
     23  * @hide
     24  */
     25 public abstract class BufferIterator {
     26     /**
     27      * Seeks to the absolute position {@code offset}, measured in bytes from the start of the
     28      * buffer.
     29      */
     30     public abstract void seek(int offset);
     31 
     32     /**
     33      * Skips forwards or backwards {@code byteCount} bytes from the current position.
     34      */
     35     public abstract void skip(int byteCount);
     36 
     37     /**
     38      * Returns the current position of the iterator within the buffer.
     39      */
     40     public abstract int pos();
     41 
     42     /**
     43      * Copies {@code byteCount} bytes from the current position into {@code dst}, starting at
     44      * {@code dstOffset}, and advances the current position {@code byteCount} bytes.
     45      *
     46      * @throws IndexOutOfBoundsException if the read / write would be outside of the buffer / array
     47      */
     48     public abstract void readByteArray(byte[] dst, int dstOffset, int byteCount);
     49 
     50     /**
     51      * Returns the byte at the current position, and advances the current position one byte.
     52      *
     53      * @throws IndexOutOfBoundsException if the read would be outside of the buffer
     54      */
     55     public abstract byte readByte();
     56 
     57     /**
     58      * Returns the 32-bit int at the current position, and advances the current position four bytes.
     59      *
     60      * @throws IndexOutOfBoundsException if the read would be outside of the buffer
     61      */
     62     public abstract int readInt();
     63 
     64     /**
     65      * Copies {@code intCount} 32-bit ints from the current position into {@code dst}, starting at
     66      * {@code dstOffset}, and advances the current position {@code 4 * intCount} bytes.
     67      *
     68      * @throws IndexOutOfBoundsException if the read / write would be outside of the buffer / array
     69      */
     70     public abstract void readIntArray(int[] dst, int dstOffset, int intCount);
     71 
     72     /**
     73      * Returns the 16-bit short at the current position, and advances the current position two bytes.
     74      *
     75      * @throws IndexOutOfBoundsException if the read would be outside of the buffer
     76      */
     77     public abstract short readShort();
     78 }
     79