com.sun.jini.jeri.internal.http
Class MessageReader

java.lang.Object
  extended by com.sun.jini.jeri.internal.http.MessageReader

 class MessageReader
extends Object

Class for reading HTTP messages. Each instance reads a single HTTP message.

Author:
Sun Microsystems, Inc.

Nested Class Summary
private  class MessageReader.BoundedInputStream
          Input stream for reading bounded content data.
private  class MessageReader.ChunkedInputStream
          Input stream for reading chunked content data.
 
Field Summary
private  InputStream cin
           
private static int CONTENT
           
private static int DONE
           
private static int HEADER
           
private  InputStream in
           
private  boolean noContent
           
private static byte[] sink
           
private  StartLine sline
           
private static int START
           
private  int state
           
 
Constructor Summary
MessageReader(InputStream in, boolean noContent)
          Creates new reader on top of given input stream.
 
Method Summary
(package private)  int availableContent()
          Returns count of available message content.
private static boolean contentIndicated(StartLine sline, Header header)
          Returns true if given start line and header indicate a content body.
(package private)  int readContent(byte[] b, int off, int len)
          Reads message content.
(package private)  Header readHeader()
          Reads in HTTP message header.
(package private) static String readLine(InputStream in)
          Reads and returns next line from stream, or null if at end of stream.
(package private)  StartLine readStartLine()
          Reads in HTTP message start line.
(package private)  Header readTrailer()
          Reads in message trailer after consuming any unread content data.
private  void updateState(int oldState, int newState)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

START

private static final int START
See Also:
Constant Field Values

HEADER

private static final int HEADER
See Also:
Constant Field Values

CONTENT

private static final int CONTENT
See Also:
Constant Field Values

DONE

private static final int DONE
See Also:
Constant Field Values

sink

private static final byte[] sink

in

private final InputStream in

noContent

private final boolean noContent

state

private int state

sline

private StartLine sline

cin

private InputStream cin
Constructor Detail

MessageReader

MessageReader(InputStream in,
              boolean noContent)
Creates new reader on top of given input stream. If noContent is true, incoming message is assumed to be bodiless (e.g., a HEAD response).

Method Detail

readStartLine

StartLine readStartLine()
                  throws IOException
Reads in HTTP message start line.

Throws:
IOException

readHeader

Header readHeader()
            throws IOException
Reads in HTTP message header.

Throws:
IOException

readContent

int readContent(byte[] b,
                int off,
                int len)
          throws IOException
Reads message content.

Throws:
IOException

availableContent

int availableContent()
               throws IOException
Returns count of available message content.

Throws:
IOException

readTrailer

Header readTrailer()
             throws IOException
Reads in message trailer after consuming any unread content data. Returns null if message doesn't have a trailer.

Throws:
IOException

readLine

static String readLine(InputStream in)
                throws IOException
Reads and returns next line from stream, or null if at end of stream. Expects ASCII lines terminated by the HTTP end-of-line sequence "\r\n".

Throws:
IOException

updateState

private void updateState(int oldState,
                         int newState)

contentIndicated

private static boolean contentIndicated(StartLine sline,
                                        Header header)
Returns true if given start line and header indicate a content body.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.