FileDocCategorySizeDatePackage
BasicHeaderElementIterator.javaAPI DocAndroid 1.5 API5706Wed May 06 22:41:10 BST 2009org.apache.http.message

BasicHeaderElementIterator

public class BasicHeaderElementIterator extends Object implements HeaderElementIterator
Basic implementation of a {@link HeaderElementIterator}.
version
$Revision: 592088 $
author
Andrea Selva
author
Oleg Kalnichevski

Fields Summary
private final HeaderIterator
headerIt
private final HeaderValueParser
parser
private HeaderElement
currentElement
private CharArrayBuffer
buffer
private ParserCursor
cursor
Constructors Summary
public BasicHeaderElementIterator(HeaderIterator headerIterator, HeaderValueParser parser)
Creates a new instance of BasicHeaderElementIterator

    
               
     
              
               
        if (headerIterator == null) {
            throw new IllegalArgumentException("Header iterator may not be null");
        }
        if (parser == null) {
            throw new IllegalArgumentException("Parser may not be null");
        }
        this.headerIt = headerIterator;
        this.parser = parser;
    
public BasicHeaderElementIterator(HeaderIterator headerIterator)

        this(headerIterator, BasicHeaderValueParser.DEFAULT);
    
Methods Summary
private voidbufferHeaderValue()

        this.cursor = null;
        this.buffer = null;
        while (this.headerIt.hasNext()) {
            Header h = this.headerIt.nextHeader();
            if (h instanceof FormattedHeader) {
                this.buffer = ((FormattedHeader) h).getBuffer();
                this.cursor = new ParserCursor(0, this.buffer.length());
                this.cursor.updatePos(((FormattedHeader) h).getValuePos());
                break;
            } else {
                String value = h.getValue();
                if (value != null) {
                    this.buffer = new CharArrayBuffer(value.length());
                    this.buffer.append(value);
                    this.cursor = new ParserCursor(0, this.buffer.length());
                    break;
                }
            }
        }
    
public booleanhasNext()

        if (this.currentElement == null) {
            parseNextElement();
        }
        return this.currentElement != null;
    
public final java.lang.Objectnext()

        return nextElement();
    
public org.apache.http.HeaderElementnextElement()

        if (this.currentElement == null) {
            parseNextElement();
        }

        if (this.currentElement == null) {
            throw new NoSuchElementException("No more header elements available");
        }

        HeaderElement element = this.currentElement;
        this.currentElement = null;
        return element;
    
private voidparseNextElement()

        // loop while there are headers left to parse
        while (this.headerIt.hasNext() || this.cursor != null) {
            if (this.cursor == null || this.cursor.atEnd()) {
                // get next header value
                bufferHeaderValue();
            }
            // Anything buffered?
            if (this.cursor != null) {
                // loop while there is data in the buffer 
                while (!this.cursor.atEnd()) {
                    HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor);
                    if (!(e.getName().length() == 0 && e.getValue() == null)) {
                        // Found something
                        this.currentElement = e;
                        return;
                    }
                }
                // if at the end of the buffer
                if (this.cursor.atEnd()) {
                    // discard it
                    this.cursor = null;
                    this.buffer = null;
                }
            }
        }
    
public voidremove()

        throw new UnsupportedOperationException("Remove not supported");