String type = request.getBodyContentType().toString();
connection.addRequestProperty(CONTENT_TYPE, type);
}
try
{
final CommitHeaderOutputStream commit = new CommitHeaderOutputStream();
CommitHeaderOutputStream.CommitCallback callback = new CommitHeaderOutputStream.CommitCallback()
{
@Override
public void commit()
{
connection.setDoOutput(true);
commitHeaders(request, connection);
OutputStream os = null;
try
{
os = connection.getOutputStream();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
commit.setDelegate(os);
}
};
commit.setHeaders(callback);
try
{
request.writeRequestBody(request.getHeadersAsObjects(), commit);
}
finally
{
commit.getDelegate().flush();
commit.getDelegate().close();
}
}
catch (IOException e)
{
throw new RuntimeException(e);