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

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

 class MessageWriter
extends Object

Class for writing HTTP messages. Each instance writes a single HTTP message.

Author:
Sun Microsystems, Inc.

Nested Class Summary
private  class MessageWriter.ChunkedOutputStream
          Output stream for writing chunked transfer-coded content.
 
Field Summary
private static int CHUNK_SIZE
           
private static int CONTENT
           
private  OutputStream cout
           
private static int DONE
           
private  Header header
           
private static int HEADER
           
private  OutputStream out
           
private static int START
           
private  int state
           
 
Constructor Summary
MessageWriter(OutputStream out, boolean chunked)
          Creates new writer on top of given output stream.
 
Method Summary
(package private)  void flush()
          Flushes written data to underlying output stream.
private  void updateState(int oldState, int newState)
           
(package private)  void writeContent(byte[] b, int off, int len)
          Writes message content.
(package private)  void writeHeader(Header header)
          "Writes" HTTP message header (the header may not actually be written until after the message content length is known).
(package private) static void writeLine(OutputStream out, String line)
          Writes line to given output stream in ASCII, terminated by HTTP end-of-line sequence "\r\n".
(package private)  void writeStartLine(StartLine line)
          Writes HTTP message start line.
(package private)  void writeTrailer(Header trailer)
          Writes message trailer (if not using chunked output, merges trailer with header before writing), completing message output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHUNK_SIZE

private static final int CHUNK_SIZE
See Also:
Constant Field Values

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

out

private final OutputStream out

cout

private final OutputStream cout

state

private int state

header

private Header header
Constructor Detail

MessageWriter

MessageWriter(OutputStream out,
              boolean chunked)
Creates new writer on top of given output stream.

Method Detail

writeStartLine

void writeStartLine(StartLine line)
              throws IOException
Writes HTTP message start line.

Throws:
IOException

writeHeader

void writeHeader(Header header)
           throws IOException
"Writes" HTTP message header (the header may not actually be written until after the message content length is known). The caller should avoid using the passed header after invoking this method.

Throws:
IOException

writeContent

void writeContent(byte[] b,
                  int off,
                  int len)
            throws IOException
Writes message content.

Throws:
IOException

writeTrailer

void writeTrailer(Header trailer)
            throws IOException
Writes message trailer (if not using chunked output, merges trailer with header before writing), completing message output. Flushes underlying output stream once trailer has been written.

Throws:
IOException

flush

void flush()
     throws IOException
Flushes written data to underlying output stream. Throws IllegalStateException if called after message has been fully written.

Throws:
IOException

writeLine

static void writeLine(OutputStream out,
                      String line)
               throws IOException
Writes line to given output stream in ASCII, terminated by HTTP end-of-line sequence "\r\n".

Throws:
IOException

updateState

private void updateState(int oldState,
                         int newState)


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