Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpcomponents Wiki" 
for change notification.

The following page has been changed by QuintinBeukes:
http://wiki.apache.org/HttpComponents/HttpEntity

------------------------------------------------------------------------------
  This is an entity which receives it's content from a !ContentProducer. 
Content producers
  are objects which produce their content on demand, by writing it out to an 
output stream. They are expected to be able produce their content every time 
they are requested to do so. So creating a !EntityTemplate, you supply a 
reference to a content producer, which effectively creates a repeatable entity.
  
- There are no standard !ContentProducers in HttpComponents. To use this entity 
you will need to extend !ContentProducer and override the writeTo(OutputStream) 
method. Inside this method you will write the full content body to the output 
stream.
+ There are no standard !ContentProducers in HttpComponents. It's basically 
just a convenience interface to allow wrapping up complex logic into an entity. 
To use this entity you will need to create a class that implements 
!ContentProducer and override the writeTo(OutputStream) method. Inside this 
method you will write the full content body to the output stream.
+ 
+ If you for instance made a HTTP server, you would serve static files with the 
FileEntity, but running CGI programs can be done with a ContentProducer, inside 
which you run the program and supply the content as it becomes available. This 
way you don't need to buffer it in a string and then use a StringEntity or 
ByteArrayEntity. Like I mentioned, a convenience class.
+ 
+ {{{#!java numbers=off
+     ContentProducer myContentProducer = new ContentProducer() {
+       @Override
+       public void writeTo(OutputStream out) throws IOException
+       {
+         out.write("ContentProducer rocks!".getBytes());
+         out.write(("Time requested: " + new Date()).getBytes());
+       }
+     };
+     HttpEntity myEntity = new EntityTemplate(myContentProducer);
+ }}}
  
  [[Anchor(FileEntity)]]
  === FileEntity ===
- ... To be completed ...
+ This entity is reads it's content body from a file. Since this is mostly used 
to stream large files of different types, you need to supply the content type 
of the file, for instance, sending a zip you would supply the content type 
"application/zip", for XML "application/xml".
+ 
+ {{{#!java numbers=off
+   File staticFile = new 
File("/path/to/a-class-software/httpcore-4.0-beta1.jar");
+   HttpEntity entity = new FileEntity(staticFile, "application/java-archive");
+ }}}
  
  [[Anchor(HttpEntityWrapper)]]
  === HttpEntityWrapper ===

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to