// Path: jflask/src/main/java/net/jflask/util/IO.java
// public class IO {
// 
//   /**
//    * Reads specified input stream until it reaches EOF.
//    */
//   public static byte[] readFully(InputStream in) throws IOException {
//     ByteArrayOutputStream bout = new ByteArrayOutputStream();
//     pipe(in, bout, false);
//     return bout.toByteArray();
//   }
// 
//   /**
//    * Reads input stream until EOF and writes all read data into output stream,
//    * then closes it.
//    */
//   public static void pipe(InputStream in, OutputStream out, boolean closeOutput)
//       throws IOException {
//     byte[] buf = new byte[1024];
//     while (true) {
//       int len = in.read(buf);
//       if (len >= 0) {
//         out.write(buf, 0, len);
//         out.flush();
//       }
//       else {
//         if (closeOutput)
//           out.close();
//         break;
//       }
//     }
//   }
// 
// }


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import com.sun.net.httpserver.HttpExchange;
import net.jflask.util.IO;

  public HttpExchange getExchange() {
    return exchange;
  }

  public String getMethod() {
    return exchange.getRequestMethod();
  }

  public String getArg(String name, String def) {
    if (qsMark == -1)
      return def;
    return parseArg(name, def, getQueryString());
  }

  private String parseArg(String name, String def, String encoded) {
    String[] tok = encoded.split("&");
    for (String s : tok) {
      if (s.startsWith(name)) {
        if (s.length() > name.length() && s.charAt(name.length()) == '=')
          return s.substring(name.length() + 1);
      }
    }
    return def;
  }

  @Override
  public String getForm(String field) {
    try {
      if (form == null)
// Path: jflask/src/main/java/net/jflask/util/IO.java
// public class IO {
// 
//   /**
//    * Reads specified input stream until it reaches EOF.
//    */
//   public static byte[] readFully(InputStream in) throws IOException {
//     ByteArrayOutputStream bout = new ByteArrayOutputStream();
//     pipe(in, bout, false);
//     return bout.toByteArray();
//   }
// 
//   /**
//    * Reads input stream until EOF and writes all read data into output stream,
//    * then closes it.
//    */
//   public static void pipe(InputStream in, OutputStream out, boolean closeOutput)
//       throws IOException {
//     byte[] buf = new byte[1024];
//     while (true) {
//       int len = in.read(buf);
//       if (len >= 0) {
//         out.write(buf, 0, len);
//         out.flush();
//       }
//       else {
//         if (closeOutput)
//           out.close();
//         break;
//       }
//     }
//   }
// 
// }


// Path: jflask/src/main/java/net/jflask/SunRequest.java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import com.sun.net.httpserver.HttpExchange;
import net.jflask.util.IO;


  public HttpExchange getExchange() {
    return exchange;
  }

  public String getMethod() {
    return exchange.getRequestMethod();
  }

  public String getArg(String name, String def) {
    if (qsMark == -1)
      return def;
    return parseArg(name, def, getQueryString());
  }

  private String parseArg(String name, String def, String encoded) {
    String[] tok = encoded.split("&");
    for (String s : tok) {
      if (s.startsWith(name)) {
        if (s.length() > name.length() && s.charAt(name.length()) == '=')
          return s.substring(name.length() + 1);
      }
    }
    return def;
  }

  @Override
  public String getForm(String field) {
    try {
      if (form == null)
        form = new String(IO.readFully(getInputStream()));