Java Code Examples for com.squareup.okhttp.internal.StrictLineReader#readLine()

The following examples show how to use com.squareup.okhttp.internal.StrictLineReader#readLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpResponseCache.java    From L.TileLayer.Cordova with MIT License 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 2
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e);
  }
}
 
Example 3
Source File: HttpResponseCache.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 4
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 5
Source File: HttpResponseCache.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 6
Source File: HttpResponseCache.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 7
Source File: HttpResponseCache.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 8
Source File: HttpResponseCache.java    From wildfly-samples with MIT License 6 votes vote down vote up
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.getBytes("US-ASCII"));
      result[i] = certificateFactory.generateCertificate(new ByteArrayInputStream(bytes));
    }
    return result;
  } catch (CertificateException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 9
Source File: HttpResponseCache.java    From bluemix-parking-meter with MIT License 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 10
Source File: HttpResponseCache.java    From android-discourse with Apache License 2.0 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * <p/>
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * <p/>
 *   AES_256_WITH_MD5
 *   2
 *   base64-encoded peerCertificate[0]
 *   base64-encoded peerCertificate[1]
 *   -1
 * }</pre>
 * 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.
 * <p/>
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 * <p/>
 * <p>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, 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();
    }
}
 
Example 11
Source File: HttpResponseCache.java    From reader with MIT License 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 12
Source File: HttpResponseCache.java    From crosswalk-cordova-android with Apache License 2.0 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 13
Source File: HttpResponseCache.java    From reader with MIT License 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 14
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 15
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 16
Source File: HttpResponseCache.java    From phonegapbootcampsite with MIT License 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 17
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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.isEmpty()) {
        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();
  }
}
 
Example 18
Source File: HttpResponseCache.java    From CordovaYoutubeVideoPlayer with MIT License 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}
 
Example 19
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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.isEmpty()) {
        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();
  }
}
 
Example 20
Source File: HttpResponseCache.java    From L.TileLayer.Cordova with MIT License 3 votes vote down vote up
/**
 * Reads an entry from an input stream. A typical entry looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 *
 * <p>A typical HTTPS file looks like this:
 * <pre>{@code
 *   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
 * }</pre>
 * 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.
 *
 * <p>Next is the response status line, followed by the number of HTTP
 * response header lines, followed by those lines.
 *
 * <p>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, 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();
  }
}