001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.mina.util.byteaccess;
021
022import java.nio.ByteOrder;
023
024import org.apache.mina.core.buffer.IoBuffer;
025
026/**
027 * Provides absolute read access to a sequence of bytes.
028 * 
029 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
030 */
031public interface IoAbsoluteReader {
032
033    /**
034     * @return the index of the first byte that can be accessed.
035     */
036    int first();
037
038    /**
039     * @return the index after the last byte that can be accessed.
040     */
041    int last();
042
043    /**
044     * @return the total number of bytes that can be accessed.
045     */
046    int length();
047
048    /**
049     * Creates an array with a view of part of this array.
050     * 
051     * @param index The starting position
052     * @param length The number of bytes to copy
053     * @return The ByteArray that is a view on the original array 
054     */
055    ByteArray slice(int index, int length);
056
057    /**
058     * @return the order of the bytes.
059     */
060    ByteOrder order();
061
062    /**
063     * @param index The starting position
064     * @return a <tt>byte</tt> from the given index.
065     */
066    byte get(int index);
067
068    /**
069     * Gets enough bytes to fill the <tt>IoBuffer</tt> from the given index.
070     * 
071     * @param index The starting position
072     * @param bb The IoBuffer that will be filled with the bytes
073     */
074    void get(int index, IoBuffer bb);
075
076    /**
077     * @param index The starting position
078     * @return a <tt>short</tt> from the given index.
079     */
080    short getShort(int index);
081
082    /**
083     * @param index The starting position
084     * @return an <tt>int</tt> from the given index.
085     */
086    int getInt(int index);
087
088    /**
089     * @param index The starting position
090     * @return a <tt>long</tt> from the given index.
091     */
092    long getLong(int index);
093
094    /**
095     * @param index The starting position
096     * @return a <tt>float</tt> from the given index.
097     */
098    float getFloat(int index);
099
100    /**
101     * @param index The starting position
102     * @return a <tt>double</tt> from the given index.
103     */
104    double getDouble(int index);
105
106    /**
107     * @param index The starting position
108     * @return a <tt>char</tt> from the given index.
109     */
110    char getChar(int index);
111}