/** * Transfer data to the server. */ protected void transfer(Env env) { super.transfer(env); CurlHttpConnection conn = getHttpConnection(); OutputStream @out = conn.getOutputStream(); //out = new TestOutputStream(out); _body.writeTo(env, out); }
/** * Transfer data to the server. */ protected void transfer(Env env) { super.transfer(env); CurlHttpConnection conn = getHttpConnection(); OutputStream @out = conn.getOutputStream(); CurlResource curl = getCurlResource(); try { BinaryInput in = curl.getUploadFile(); long length = curl.getUploadFileSize(); long totalWritten = 0; if (curl.getReadCallback() != null) { Callable callback = curl.getReadCallback(); Value fileV = env.wrapJava(in); LongValue lengthV = LongValue.create(length); while (totalWritten < length) { StringValue str = callback.call(env, fileV, lengthV).ToStringValue(env); int count = str.length(); if (count == 0) { break; } str.writeTo(out); totalWritten += count; } } else { byte [] buffer = new byte[1024 * 4]; while (totalWritten < length) { int count = in.read(buffer, 0, buffer.length); if (count < 0) { break; } @out.write(buffer, 0, count); totalWritten += count; } } } finally { @out.close(); } }