Java Doc for HttpOutputStream.java in  » Net » SkunkDAV » HTTPClient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » SkunkDAV » HTTPClient 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.io.OutputStream
      HTTPClient.HttpOutputStream

HttpOutputStream
public class HttpOutputStream extends OutputStream implements GlobalConstants(Code)
This class provides an output stream for requests. The stream must first be associated with a request before it may be used; this is done by passing it to one of the request methods in HTTPConnection. Example:
 OutputStream out = new HttpOutputStream(12345);
 rsp = con.Post("/cgi-bin/my_cgi", out);
 out.write(...);
 out.close();
 if (rsp.getStatusCode() >= 300)
 ...
 

There are two constructors for this class, one taking a length parameter, and one without any parameters. If the stream is created with a length then the request will be sent with the corresponding Content-length header and anything written to the stream will be written on the socket immediately. This is the preferred way. If the stream is created without a length then one of two things will happen: if, at the time of the request, the server is known to understand HTTP/1.1 then each write() will send the data immediately using the chunked encoding. If, however, either the server version is unknown (because this is first request to that server) or the server only understands HTTP/1.0 then all data will be written to a buffer first, and only when the stream is closed will the request be sent.

Another reason that using the HttpOutputStream(length) constructor is recommended over the HttpOutputStream() one is that some HTTP/1.1 servers do not allow the chunked transfer encoding to be used when POSTing to a cgi script. This is because the way the cgi API is defined the cgi script expects a Content-length environment variable. If the data is sent using the chunked transfer encoding however, then the server would have to buffer all the data before invoking the cgi so that this variable could be set correctly. Not all servers are willing to do this.

If you cannot use the HttpOutputStream(length) constructor and are having problems sending requests (usually a 411 response) then you can try setting the system property HTTPClient.dontChunkRequests to true (this needs to be done either on the command line or somewhere in the code before the HTTPConnection is first accessed). This will prevent the client from using the chunked encoding in this case and will cause the HttpOutputStream to buffer all the data instead, sending it only when close() is invoked.

The behaviour of a request sent with an output stream may differ from that of a request sent with a data parameter. The reason for this is that the various modules cannot resend a request which used an output stream. Therefore such things as authorization and retrying of requests won't be done by the HTTPClient for such requests.
version:
   0.3-2 18/06/1999
author:
   Ronald Tschalär
since:
   V0.3




Constructor Summary
public  HttpOutputStream()
     Creates an output stream of unspecified length.
public  HttpOutputStream(int length)
     This creates an output stream which will take length bytes of data.

Method Summary
public synchronized  voidclose()
     Closes the stream and causes the data to be sent if it has not already been done so.
public  intgetLength()
     Returns the number of bytes this stream is willing to accept, or -1 if it is unbounded.
synchronized  ResponsegetResponse()
     Return the response we got from sendRequest().
public  NVPair[]getTrailers()
     Gets the trailers which were set with setTrailers().
 voidgoAhead(Request req, OutputStream os, int con_to)
     Associates this stream with a request and the actual output stream.
 voidignoreData(Request req)
     Setup this stream to dump the data to the great bit-bucket in the sky.
public  voidsetTrailers(NVPair[] trailers)
     Sets the trailers to be sent if the output is sent with the chunked transfer encoding.
public  StringtoString()
     produces a string describing this stream.
public  voidwrite(int b)
     Writes a single byte on the stream.
public synchronized  voidwrite(byte[] buf, int off, int len)
     Writes an array of bytes on the stream.


Constructor Detail
HttpOutputStream
public HttpOutputStream()(Code)
Creates an output stream of unspecified length. Note that it is highly recommended that this constructor be avoided where possible and HttpOutputStream(int) used instead.
See Also:   HttpOutputStream.HttpOutputStream(int)



HttpOutputStream
public HttpOutputStream(int length)(Code)
This creates an output stream which will take length bytes of data.
Parameters:
  length - the number of bytes which will be sent over this stream




Method Detail
close
public synchronized void close() throws IOException, IllegalAccessError(Code)
Closes the stream and causes the data to be sent if it has not already been done so. This method must be invoked when all data has been written.
exception:
  IOException - if any exception is thrown by the underlyingsocket, or if too few bytes were written.
exception:
  IllegalAccessError - if this stream has not been associatedwith a request yet.



getLength
public int getLength()(Code)
Returns the number of bytes this stream is willing to accept, or -1 if it is unbounded. the number of bytes



getResponse
synchronized Response getResponse()(Code)
Return the response we got from sendRequest(). This waits until the request has actually been sent. the response returned by sendRequest()



getTrailers
public NVPair[] getTrailers()(Code)
Gets the trailers which were set with setTrailers(). an array of header fields
See Also:   HttpOutputStream.setTrailers(NVPair[])



goAhead
void goAhead(Request req, OutputStream os, int con_to)(Code)
Associates this stream with a request and the actual output stream. No other methods in this class may be invoked until this method has been invoked by the HTTPConnection.
Parameters:
  req - the request this stream is to be associated with
Parameters:
  os - the underlying output stream to write our data to, or nullif we should write to a ByteArrayOutputStream instead.
Parameters:
  con_to - connection timeout to use in sendRequest()



ignoreData
void ignoreData(Request req)(Code)
Setup this stream to dump the data to the great bit-bucket in the sky. This is needed for when a module handles the request directly.
Parameters:
  req - the request this stream is to be associated with



setTrailers
public void setTrailers(NVPair[] trailers)(Code)
Sets the trailers to be sent if the output is sent with the chunked transfer encoding. These must be set before the output stream is closed for them to be sent.

Any trailers set here should be mentioned in a Trailer header in the request (see section 14.40 of draft-ietf-http-v11-spec-rev-06.txt).

This method (and its related getTrailers())) are in this class and not in Request because setting trailers is something an application may want to do, not only modules.
Parameters:
  trailers - an array of header fields




toString
public String toString()(Code)
produces a string describing this stream. a string containing the name and the length



write
public void write(int b) throws IOException, IllegalAccessError(Code)
Writes a single byte on the stream. It is subject to the same rules as write(byte[], int, int).
Parameters:
  b - the byte to write
exception:
  IOException - if any exception is thrown by the socket
See Also:   HttpOutputStream.write(byte[],int,int)



write
public synchronized void write(byte[] buf, int off, int len) throws IOException, IllegalAccessError(Code)
Writes an array of bytes on the stream. This method may not be used until this stream has been passed to one of the methods in HTTPConnection (i.e. until it has been associated with a request).
Parameters:
  buf - an array containing the data to write
Parameters:
  off - the offset of the data whithin the buffer
Parameters:
  len - the number bytes (starting at off) to write
exception:
  IOException - if any exception is thrown by the socket, orif writing len bytes would cause more bytes tobe written than this stream is willing to accept.
exception:
  IllegalAccessError - if this stream has not been associatedwith a request yet



Methods inherited from java.io.OutputStream
public void close() throws IOException(Code)(Java Doc)
public void flush() throws IOException(Code)(Java Doc)
abstract public void write(int b) throws IOException(Code)(Java Doc)
public void write(byte b) throws IOException(Code)(Java Doc)
public void write(byte b, int off, int len) throws IOException(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.