dirkv       01/08/13 10:09:53

  Modified:    org/apache/commons/httpclient/methods/PutMethod.java
  Log:
  Just noticed that my patch from 8 may isn't committed yet...
  When you try to send data to the server with as input a byte[] or and
  InputStream (is streamed to internal byte[]) then that byte[] is first

  converted to a String (normal encoding) and then back to an utf-8
encoded
  byte[]. For real binary data this goes horribly wrong.
  From now on just stream the data directly to the server.


  @@ -81,6 +81,7 @@
    * PUT Method.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  + * @author Dirk Verbeeck
    */
   public class PutMethod
       extends HttpMethodBase {
  @@ -193,13 +194,13 @@


       /**
  -     * Is the query body submitted through an InputStream of with a
String.
  -     * If an InputStream is available, it's used.
  +     * Is the query body streamed to the server.
  +     * For this method this is always true.
        *
  -     * @return boolean True if the content is avalable in an
InputStream
  +     * @return boolean true
        */
       public boolean isStreamedQuery() {
  -        return ((file != null) || (url != null));
  +        return true;
       }


  @@ -217,18 +218,12 @@

       /**
        * Generate the query body.
  +     * Not used, always stream the content to the server
        *
        * @return String query
        */
       public String generateQuery() {
  -        if (query != null){
  -            return query;
  -        }
  -        if (data == null) {
  -            return "";
  -        } else {
  -            return new String(data);
  -        }
  +        return "";
       }


  @@ -240,12 +235,17 @@
           throws IOException {

           InputStream inputStream = null;
  -        if (file != null) {
  +        if (data != null) {
  +            out.write(data,0,data.length);
  +            return;
  +        } else if (file != null) {
               inputStream = new FileInputStream(file);
           } else if (url != null) {
               inputStream = url.openConnection().getInputStream();
  +        } else {
  +            return;
           }
  -
  +
           byte[] buffer = new byte[4096];
           int nb = 0;
           while (true) {



Reply via email to