Hi ,
I am trying to upload video to you tube using
java.net.HttpURLConnection with setChunkedStreamingMode(8*1024)
property and content type is multipart/binay; and even i tried chunked
also. I am getting following exception.
If i don't use setChunkedStreamingMode this property output stream is
using internal buffer increasing while uploading data in chunks which
is causing heap size to grow and throwing out of memory exception.
java.net.SocketException: Broken pipe
at org.apache.harmony.luni.platform.OSNetworkSystem.sendStreamImpl
(Native Method)
at org.apache.harmony.luni.platform.OSNetworkSystem.sendStream
(OSNetworkSystem.java:241)
at org.apache.harmony.luni.net.PlainSocketImpl.write
(PlainSocketImpl.java:566)
at org.apache.harmony.luni.net.SocketOutputStream.write
(SocketOutputStream.java:50)
at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection
$HttpOutputStream.output(HttpURLConnection.java:550)
at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection
$HttpOutputStream.write(HttpURLConnection.java:658)
at java.io.DataOutputStream.write(DataOutputStream.java:107)
here is my code.
DataOutputStream body = new DataOutputStream
(httpWebConnection.getOutputStream());
body.write(requestBody);
body.flush();
//*****
BufferedInputStream uploadStream = new
BufferedInputStream(new FileInputStream(completeFilePathWithName),
size);
// write videoData in stream
byte[] buf = new byte[size];
int len = -1;
int count = 1;
int bufLen =0;
int bytesAvailable;
while ((bytesAvailable = uploadStream.available())
> 0)
{
int bufferSize = Math.min(bytesAvailable,
size);
byte[] buffer = new byte[bufferSize];
int bytesRead = uploadStream.read(buffer, 0,
bufferSize);
body.write(buffer, 0, bytesRead);
body.flush();
bufLen = bufLen + bytesRead;
try
{
Thread.sleep(600);
}catch(Exception e)
{
e.printStackTrace();
}
}
uploadStream.close();
uploadStream = null;
body.write(endBoundry.getBytes());
body.flush();
body.close();
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---