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 com.android.i18n.timezone.internal; 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 */ seek(int offset)30 public abstract void seek(int offset); 31 32 /** 33 * Skips forwards or backwards {@code byteCount} bytes from the current position. 34 */ skip(int byteCount)35 public abstract void skip(int byteCount); 36 37 /** 38 * Returns the current position of the iterator within the buffer. 39 */ pos()40 public abstract int pos(); 41 42 /** 43 * Copies {@code byteCount} bytes from the current position into {@code bytes}, starting at 44 * {@code arrayOffset}, and advances the current position {@code byteCount} bytes. 45 * 46 * @throws IndexOutOfBoundsException if the read / write would be outside of the buffer / array 47 */ readByteArray(byte[] bytes, int arrayOffset, int byteCount)48 public abstract void readByteArray(byte[] bytes, int arrayOffset, 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 */ readByte()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 */ readInt()62 public abstract int readInt(); 63 64 /** 65 * Copies {@code intCount} 32-bit ints from the current position into {@code ints}, starting at 66 * {@code arrayOffset}, 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 */ readIntArray(int[] ints, int arrayOffset, int intCount)70 public abstract void readIntArray(int[] ints, int arrayOffset, int intCount); 71 72 /** 73 * Copies {@code longCount} 64-bit ints from the current position into {@code longs}, starting 74 * at {@code arrayOffset}, and advances the current position {@code 8 * longCount} bytes. 75 * 76 * @throws IndexOutOfBoundsException if the read / write would be outside of the buffer / array 77 */ readLongArray(long[] longs, int arrayOffset, int longCount)78 public abstract void readLongArray(long[] longs, int arrayOffset, int longCount); 79 80 /** 81 * Returns the 16-bit short at the current position, and advances the current position two bytes. 82 * 83 * @throws IndexOutOfBoundsException if the read would be outside of the buffer 84 */ readShort()85 public abstract short readShort(); 86 } 87