1d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes/*
2d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * Copyright (C) 2010 The Android Open Source Project
3d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes *
4d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * you may not use this file except in compliance with the License.
6d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * You may obtain a copy of the License at
7d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes *
8d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes *
10d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * See the License for the specific language governing permissions and
14d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * limitations under the License.
15d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes */
16d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes
17d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughespackage libcore.io;
18d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes
19d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes/**
20d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * Iterates over big- or little-endian bytes. See {@link MemoryMappedFile#bigEndianIterator} and
21d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * {@link MemoryMappedFile#littleEndianIterator}.
22d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes *
23d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes * @hide don't make this public without adding bounds checking.
24d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes */
2543a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughespublic abstract class BufferIterator {
26d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes    /**
27b5bde2fd72189192b52e726a2d606d70c3c8a34bElliott Hughes     * Seeks to the absolute position {@code offset}, measured in bytes from the start.
28b5bde2fd72189192b52e726a2d606d70c3c8a34bElliott Hughes     */
29b5bde2fd72189192b52e726a2d606d70c3c8a34bElliott Hughes    public abstract void seek(int offset);
30b5bde2fd72189192b52e726a2d606d70c3c8a34bElliott Hughes
31b5bde2fd72189192b52e726a2d606d70c3c8a34bElliott Hughes    /**
32d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * Skips forwards or backwards {@code byteCount} bytes from the current position.
33d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     */
3443a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    public abstract void skip(int byteCount);
35d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes
36d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes    /**
37d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * Copies {@code byteCount} bytes from the current position into {@code dst}, starting at
38d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * {@code dstOffset}, and advances the current position {@code byteCount} bytes.
39d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     */
4043a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    public abstract void readByteArray(byte[] dst, int dstOffset, int byteCount);
41d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes
42d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes    /**
43d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * Returns the byte at the current position, and advances the current position one byte.
44d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     */
4543a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    public abstract byte readByte();
46d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes
47d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes    /**
48d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * Returns the 32-bit int at the current position, and advances the current position four bytes.
49d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     */
5043a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    public abstract int readInt();
51d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes
52d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes    /**
53d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * Copies {@code intCount} 32-bit ints from the current position into {@code dst}, starting at
54d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     * {@code dstOffset}, and advances the current position {@code 4 * intCount} bytes.
55d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes     */
5643a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    public abstract void readIntArray(int[] dst, int dstOffset, int intCount);
5743a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes
5843a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    /**
5943a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes     * Returns the 16-bit short at the current position, and advances the current position two bytes.
6043a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes     */
6143a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes    public abstract short readShort();
62d6b9f2e0e9640ff9c896b394716cf5e7eee6e257Elliott Hughes}
63