Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

httpClient apache library - managing streaming http connection help!

user13756783Feb 13 2011 — edited Feb 13 2011
hi,


i have a problem.. I try to read from a web server that stream video and audio content media : flv type
i make http request using HttpGet class from org.apache.http.client.methods to this server url like this :

HttpGet get = new HttpGet(url)
HttpResponse response = myHttpClientObject.execute(get);

but when i try to read content in a buffer like this:

entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();

System.out.println("**Entity content-length " + entity.getContentLength()); //it is 2147483647!

byte[] b = EntityUtils.toByteArray(entity); <-- using this utility with a dinamic resizing array of bytes

i get a
**Entity content-length 2147483647
Exception in thread "pool-1-thread-3" java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
at org.apache.http.util.ByteArrayBuffer.<init>(ByteArrayBuffer.java:55)
at org.apache.http.util.EntityUtils.toByteArray(EntityUtils.java:96)

beacuse the constructor of ByteArrayBuffer creat a new byte[2147483647] array

what is wrong..i suppose that because my resource is not static i must use a chunk mode, really?? but how i can use it with HttpGet??.. i think HttpPot is not supported by server beacuse
i get a http page with a forbidden message(you're not authorized). But using a HttpGet and read by a inputStreamer (not the right choice with 8 bit content type) i get
the streaming source:

//StringBuffer httpResponse = new StringBuffer();
// input = new BufferedReader(new InputStreamReader(instream));
// String resp = "null";
// while (resp != null && !(resp).equals("")) {
// log.log(Level.INFO, resp);
// resp = input.readLine();
// httpResponse.append(resp);
// }

I have to get this output and send it to a vlc player or any kind of flv stream player ..

thank you

Bye
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 13 2011
Added on Feb 13 2011
1 comment
997 views