1bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/**************************************************************** 2bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Licensed to the Apache Software Foundation (ASF) under one * 3bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * or more contributor license agreements. See the NOTICE file * 4bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * distributed with this work for additional information * 5bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * regarding copyright ownership. The ASF licenses this file * 6bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * to you under the Apache License, Version 2.0 (the * 7bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * "License"); you may not use this file except in compliance * 8bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * with the License. You may obtain a copy of the License at * 9bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * * 10bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * http://www.apache.org/licenses/LICENSE-2.0 * 11bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * * 12bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Unless required by applicable law or agreed to in writing, * 13bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * software distributed under the License is distributed on an * 14bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * KIND, either express or implied. See the License for the * 16bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * specific language governing permissions and limitations * 17bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * under the License. * 18bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook ****************************************************************/ 19bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 20bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpackage org.apache.james.mime4j.decoder; 21bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 22bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.util.Iterator; 23bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 24bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpublic class ByteQueue { 25bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 26bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook private UnboundedFifoByteBuffer buf; 27bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook private int initialCapacity = -1; 28bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 29bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public ByteQueue() { 30bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook buf = new UnboundedFifoByteBuffer(); 31bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 32bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 33bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public ByteQueue(int initialCapacity) { 34bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook buf = new UnboundedFifoByteBuffer(initialCapacity); 35bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook this.initialCapacity = initialCapacity; 36bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 37bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 38bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public void enqueue(byte b) { 39bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook buf.add(b); 40bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 41bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 42bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public byte dequeue() { 43bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return buf.remove(); 44bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 45bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 46bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public int count() { 47bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return buf.size(); 48bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 49bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 50bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public void clear() { 51bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook if (initialCapacity != -1) 52bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook buf = new UnboundedFifoByteBuffer(initialCapacity); 53bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook else 54bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook buf = new UnboundedFifoByteBuffer(); 55bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 56bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 57bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook public Iterator iterator() { 58bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook return buf.iterator(); 59bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook } 60bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 61bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook 62bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook} 63