private boolean handshake() throws Exception {
    URL homePage = new URL("http://mangaonweb.com/viewer.do?ctsn=" + ctsn);

    HttpURLConnection urlConn = (HttpURLConnection) homePage.openConnection();
    urlConn.connect();
    if (urlConn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return (false);

    // save the cookie
    String headerName = null;
    for (int i = 1; (headerName = urlConn.getHeaderFieldKey(i)) != null; i++) {
      if (headerName.equals("Set-Cookie")) {
        cookies = urlConn.getHeaderField(i);
      }
    }

    // save cdn and crcod
    String page = "", line;
    BufferedReader stream =
        new BufferedReader(new InputStreamReader(urlConn.getInputStream(), "UTF-8"));
    while ((line = stream.readLine()) != null) page += line;

    cdn = param(page, "cdn");
    crcod = param(page, "crcod");

    return (true);
  }
  private byte[] downloadByteArray(URL url) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("Cookie", cookies);
    if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return (null);

    InputStream in = conn.getInputStream();
    byte[] buf = new byte[conn.getContentLength()];
    int read, offset = 0;
    while ((read = in.read(buf, offset, buf.length - offset)) != -1) {
      offset += read;
    }
    return (buf);
  }