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.james.mime4j.util;
021
022/**
023 * An immutable sequence of bytes.
024 */
025public interface ByteSequence {
026
027    /**
028     * An empty byte sequence.
029     */
030    ByteSequence EMPTY = new EmptyByteSequence();
031
032    /**
033     * Returns the length of this byte sequence.
034     *
035     * @return the number of <code>byte</code>s in this sequence.
036     */
037    int length();
038
039    /**
040     * Returns the <code>byte</code> value at the specified index.
041     *
042     * @param index
043     *            the index of the <code>byte</code> value to be returned.
044     * @return the corresponding <code>byte</code> value
045     * @throws IndexOutOfBoundsException
046     *             if <code>index < 0 || index >= length()</code>.
047     */
048    byte byteAt(int index);
049
050    /**
051     * Copies the contents of this byte sequence into a newly allocated byte
052     * array and returns that array.
053     *
054     * @return a byte array holding a copy of this byte sequence.
055     */
056    byte[] toByteArray();
057
058}