/*
     * Reads an entry from an input stream. A typical entry looks like this:
     *   http://google.com/foo
     *   GET
     *   2
     *   Accept-Language: fr-CA
     *   Accept-Charset: UTF-8
     *   HTTP/1.1 200 OK
     *   3
     *   Content-Type: image/png
     *   Content-Length: 100
     *   Cache-Control: max-age=600
     *
     * A typical HTTPS file looks like this:
     *   https://google.com/foo
     *   GET
     *   2
     *   Accept-Language: fr-CA
     *   Accept-Charset: UTF-8
     *   HTTP/1.1 200 OK
     *   3
     *   Content-Type: image/png
     *   Content-Length: 100
     *   Cache-Control: max-age=600
     *
     *   AES_256_WITH_MD5
     *   2
     *   base64-encoded peerCertificate[0]
     *   base64-encoded peerCertificate[1]
     *   -1
     *
     * The file is newline separated. The first two lines are the URL and
     * the request method. Next is the number of HTTP Vary request header
     * lines, followed by those lines.
     *
     * Next is the response status line, followed by the number of HTTP
     * response header lines, followed by those lines.
     *
     * HTTPS responses also contain SSL session information. This begins
     * with a blank line, and then a line containing the cipher suite. Next
     * is the length of the peer certificate chain. These certificates are
     * base64-encoded and appear each on their own line. The next line
     * contains the length of the local certificate chain. These
     * certificates are also base64-encoded and appear each on their own
     * line. A length of -1 is used to encode a null array.
     */
    public Entry(InputStream in) throws IOException {
      try {
        StrictLineReader reader = new StrictLineReader(in, Charsets.US_ASCII);
        uri = reader.readLine();
        requestMethod = reader.readLine();
        varyHeaders = new RawHeaders();
        int varyRequestHeaderLineCount = reader.readInt();
        for (int i = 0; i < varyRequestHeaderLineCount; i++) {
          varyHeaders.addLine(reader.readLine());
        }

        responseHeaders = new RawHeaders();
        responseHeaders.setStatusLine(reader.readLine());
        int responseHeaderLineCount = reader.readInt();
        for (int i = 0; i < responseHeaderLineCount; i++) {
          responseHeaders.addLine(reader.readLine());
        }

        //                if (isHttps()) {
        //                    String blank = reader.readLine();
        //                    if (blank.length() != 0) {
        //                        throw new IOException("expected \"\" but was \"" + blank + "\"");
        //                    }
        //                    cipherSuite = reader.readLine();
        //                    peerCertificates = readCertArray(reader);
        //                    localCertificates = readCertArray(reader);
        //                } else {
        cipherSuite = null;
        peerCertificates = null;
        localCertificates = null;
        //                }
      } finally {
        in.close();
      }
    }
 private Certificate[] readCertArray(StrictLineReader reader) throws IOException {
   int length = reader.readInt();
   if (length == -1) {
     return null;
   }
   try {
     CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
     Certificate[] result = new Certificate[length];
     for (int i = 0; i < result.length; i++) {
       String line = reader.readLine();
       byte[] bytes = Base64.decode(line, Base64.DEFAULT);
       result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
     }
     return result;
   } catch (CertificateException e) {
     throw new IOException(e.getMessage());
   }
 }