git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5073 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
danielr 2008-08-22 23:46:32 +00:00
parent 5192081283
commit 4d937f6b21
2 changed files with 18 additions and 4 deletions

View File

@ -986,9 +986,17 @@ public final class httpdProxyHandler {
// input so we have to end it to do the request
final long requestLength = requestHeader.contentLength();
if(requestLength > -1) {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
serverFileUtils.copy(body, buffer, requestLength);
body = new ByteArrayInputStream(buffer.toByteArray());
final byte[] bodyData;
if(requestLength == 0) {
// no body
bodyData = new byte[0];
} else {
// read content-length bytes into memory
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
serverFileUtils.copy(body, buffer, requestLength);
bodyData = buffer.toByteArray();
}
body = new ByteArrayInputStream(bodyData);
}
JakartaCommonsHttpResponse res = null;
try {

View File

@ -69,7 +69,7 @@ public final class serverFileUtils {
*
* @param source InputStream
* @param dest OutputStream
* @param count the total amount of bytes to copy (-1 for all)
* @param count the total amount of bytes to copy (-1 for all, else must be greater than zero)
* @return Total number of bytes copied.
* @throws IOException
*
@ -79,6 +79,12 @@ public final class serverFileUtils {
* @see #copy(File source, File dest)
*/
public static long copy(final InputStream source, final OutputStream dest, final long count) throws IOException {
assert count == -1 || count > 0 : "precondition violated: count == -1 || count > 0 (nothing to copy)";
if(count == 0) {
// no bytes to copy
return 0;
}
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int chunkSize = (int) ((count > 0) ? Math.min(count, DEFAULT_BUFFER_SIZE) : DEFAULT_BUFFER_SIZE);