Hi folks,

I've been building a WebDAV client using Apache Webdav... which uses the
commons httpclient.
I ran into an issue with binary data , when using non-streamed calls:

I call PutMethod.sendData(byte[]).

HttpClient.executeMethod later calls sendRequestHeaders,
which calls PutMethod.generateQuery,
which converts the byte array to a String with: new String(data);
sendRequestHeaders immediately converts that back to a byte array with:
String.getBytes("UTF8");

At this point, the binary data is corrupt.  0x81 becomes 0x3f, etc.
I tried changing PutMethod's generateQuery to: new String(data,"UTF8"), but
all bytes over 0x7f get corrupted.

So here's the question, or possibly the solution...
<IMHO>
Converting from byte[] to String back to byte[] doesn't make much sense to
me.  If a non-streamed query must be returned as a String, then only
sendData(String) should use a non-streamed query.
</IMHO>
To avoid this, how about changing PutMethod as follows, to use the stream
method:

sendData(InputStream) could simply save the inputStream to a member variable
("dataInputStream"?).  This has the side benefit of not reading the entire
input stream into memory for a PUT call.

sendData(byte[] data) could then simply call sendData(new
ByteArrayInputStream(data));

sendData(String) could simply save the String ("stringData"?), and return it
in generateQuery().

isStreamedQuery(), streamQuery(), and generateQuery() get updated
appropriately.

Thoughts/comments/concerns?
Thanks much,
Mat





Reply via email to