import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class HttpUtil {
  public static int pipe(InputStream in, OutputStream out, int limit)
    throws IOException
  {
    byte[] buffer = new byte[8 * 1024];
    int total = 0;
    int c;
    while (limit < 0 || total < limit) {
      int max = buffer.length;
      if (limit >= 0 && max > (limit - total)) {
        max = limit - total;
      }
      c = in.read(buffer, 0, max);
      out.write(buffer, 0, c);
      total += c;
    }
    return total;
  }

  public static String readLine(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    boolean sawCarriageReturn = false;
    while (true) {
      int c = in.read();
      switch (c) {
      case -1:
        return sb.length() > 0 ? sb.toString() : null;
     
      case '\r':
        sawCarriageReturn = true;
        break;

      case '\n':
        if (sawCarriageReturn) {
          return sb.toString();
        }
        // fall though

      default:
        sb.append((char) c);
        sawCarriageReturn = false;
        break;
      }
    }
  }
}

@@ -263,19 +263,8 @@
  0;%0A
-    int c;%0A
     
@@ -423,16 +423,20 @@
 %7D%0A      
+int 
 c = in.r
@@ -456,16 +456,37 @@
 , max);%0A
+      if (c %3E 0) %7B%0A  
       ou
@@ -514,16 +514,18 @@
 ;%0A      
+  
 total +=
@@ -528,16 +528,54 @@
 l += c;%0A
+      %7D else %7B%0A        break;%0A      %7D%0A
     %7D%0A  

fix attempt to write -1 bytes in HttpUtil