net.noderunner.http
Class ByteArrayDataPoster

java.lang.Object
  extended by net.noderunner.http.ByteArrayDataPoster
All Implemented Interfaces:
DataPoster

public class ByteArrayDataPoster
extends java.lang.Object
implements DataPoster

A utility class for sending an array of bytes to an HTTP server or client. Example usage:

 HttpClient client = new RetryHttpClient("http://example.net");
 byte buf[] = "This is only a test".getBytes();
 DataPoster dataPoster = new ByteArrayDataPoster(buf);
 RequestLine rl = new RequestLineImpl( ... );
 ClientRequest request = new ClientRequestImpl(rl, dataPoster);

 client.writeRequest(request);
 ClientResponse response = client.readResponse();
 


Constructor Summary
ByteArrayDataPoster(byte[] data)
          Constructs a ByteArrayDataPoster, which will send an entire byte array.
ByteArrayDataPoster(byte[] data, int off, int len)
          Constructs a ByteArrayDataPoster which will send part of a byte array.
 
Method Summary
 void sendData(java.io.OutputStream os)
          Writes the byte array to the supplied output stream.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteArrayDataPoster

public ByteArrayDataPoster(byte[] data)
Constructs a ByteArrayDataPoster, which will send an entire byte array.


ByteArrayDataPoster

public ByteArrayDataPoster(byte[] data,
                           int off,
                           int len)
Constructs a ByteArrayDataPoster which will send part of a byte array.

Parameters:
data - source data array
off - zero-based offset in source
len - length of array to send
Method Detail

sendData

public void sendData(java.io.OutputStream os)
              throws java.io.IOException
Writes the byte array to the supplied output stream.

Specified by:
sendData in interface DataPoster
Parameters:
os - output stream to send data to
Throws:
java.io.IOException - if data could not be written

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.