// 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/util/Log.java
// public class Log {
// 
//   public static final boolean DEBUG = Boolean.getBoolean("debug");
// 
//   public static void warn(Object msg) {
//     System.err.println("WARN: " + msg);
//   }
// 
//   public static void error(Object msg) {
//     System.err.println("ERROR: " + msg);
//   }
// 
//   public static void error(Object msg, Throwable t) {
//     System.err.println("ERROR: " + msg);
//     t.printStackTrace();
//   }
// 
//   public static void info(Object msg) {
//     System.err.println("INFO: " + msg);
//   }
// 
//   public static void debug(Object msg) {
//     if (DEBUG)
//       System.err.println("DEBUG: " + msg);
//   }
// 
// }


import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Arrays;
import com.sun.net.httpserver.HttpExchange;
import net.jflask.util.IO;
import net.jflask.util.Log;
        res[j++] = i;
      }
      if (tok[i].charAt(0) == '*') {
        if (i != tok.length - 1)
          throw new IllegalArgumentException("Invalid route: " + rootURI);
        res[j++] = i;
        splat = i;
      }
    }
    return Arrays.copyOf(res, j);
  }

  /**
   * @return true when request was handled, false when it was ignored (eg. not
   * applicable)
   */
  @SuppressWarnings("unchecked")
  public boolean handle(HttpExchange r,
                        String[] uri,
                        Response resp) throws Exception {

    if (!isApplicable(r, uri))
      return false;

    if (loginRequired && !ctx.app.checkLoggedIn(r)) {
      return true;
    }

    Object[] args = extractArgs(uri);

// 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/util/Log.java
// public class Log {
// 
//   public static final boolean DEBUG = Boolean.getBoolean("debug");
// 
//   public static void warn(Object msg) {
//     System.err.println("WARN: " + msg);
//   }
// 
//   public static void error(Object msg) {
//     System.err.println("ERROR: " + msg);
//   }
// 
//   public static void error(Object msg, Throwable t) {
//     System.err.println("ERROR: " + msg);
//     t.printStackTrace();
//   }
// 
//   public static void info(Object msg) {
//     System.err.println("INFO: " + msg);
//   }
// 
//   public static void debug(Object msg) {
//     if (DEBUG)
//       System.err.println("DEBUG: " + msg);
//   }
// 
// }


// Path: jflask/src/main/java/net/jflask/MethodHandler.java
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Arrays;
import com.sun.net.httpserver.HttpExchange;
import net.jflask.util.IO;
import net.jflask.util.Log;

        res[j++] = i;
      }
      if (tok[i].charAt(0) == '*') {
        if (i != tok.length - 1)
          throw new IllegalArgumentException("Invalid route: " + rootURI);
        res[j++] = i;
        splat = i;
      }
    }
    return Arrays.copyOf(res, j);
  }

  /**
   * @return true when request was handled, false when it was ignored (eg. not
   * applicable)
   */
  @SuppressWarnings("unchecked")
  public boolean handle(HttpExchange r,
                        String[] uri,
                        Response resp) throws Exception {

    if (!isApplicable(r, uri))
      return false;

    if (loginRequired && !ctx.app.checkLoggedIn(r)) {
      return true;
    }

    Object[] args = extractArgs(uri);

    if (Log.DEBUG)