Search in sources :

Example 6 with GzipSource

use of okio.GzipSource in project okhttp by square.

the class PublicSuffixDatabaseTest method allPublicSuffixes.

@Test
public void allPublicSuffixes() throws IOException {
    InputStream resource = PublicSuffixDatabaseTest.class.getClassLoader().getResourceAsStream(PUBLIC_SUFFIX_RESOURCE);
    BufferedSource source = Okio.buffer(new GzipSource(Okio.source(resource)));
    int length = source.readInt();
    Buffer buffer = new Buffer();
    buffer.write(source, length);
    resource.close();
    while (!buffer.exhausted()) {
        String publicSuffix = buffer.readUtf8LineStrict();
        if (publicSuffix.contains("*")) {
            // A wildcard rule, let's replace the wildcard with a value.
            publicSuffix = publicSuffix.replaceAll("\\*", "square");
        }
        assertNull(publicSuffixDatabase.getEffectiveTldPlusOne(publicSuffix));
        String test = "foobar." + publicSuffix;
        assertEquals(test, publicSuffixDatabase.getEffectiveTldPlusOne(test));
    }
}
Also used : GzipSource(okio.GzipSource) Buffer(okio.Buffer) InputStream(java.io.InputStream) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 7 with GzipSource

use of okio.GzipSource in project okhttp by square.

the class PublicSuffixDatabase method readTheList.

private void readTheList() {
    byte[] publicSuffixListBytes = null;
    byte[] publicSuffixExceptionListBytes = null;
    InputStream is = PublicSuffixDatabase.class.getClassLoader().getResourceAsStream(PUBLIC_SUFFIX_RESOURCE);
    if (is != null) {
        BufferedSource bufferedSource = Okio.buffer(new GzipSource(Okio.source(is)));
        try {
            int totalBytes = bufferedSource.readInt();
            publicSuffixListBytes = new byte[totalBytes];
            bufferedSource.readFully(publicSuffixListBytes);
            int totalExceptionBytes = bufferedSource.readInt();
            publicSuffixExceptionListBytes = new byte[totalExceptionBytes];
            bufferedSource.readFully(publicSuffixExceptionListBytes);
        } catch (IOException e) {
            Platform.get().log(Platform.WARN, "Failed to read public suffix list", e);
            publicSuffixListBytes = null;
            publicSuffixExceptionListBytes = null;
        } finally {
            closeQuietly(bufferedSource);
        }
    }
    synchronized (this) {
        this.publicSuffixListBytes = publicSuffixListBytes;
        this.publicSuffixExceptionListBytes = publicSuffixExceptionListBytes;
    }
    readCompleteLatch.countDown();
}
Also used : GzipSource(okio.GzipSource) InputStream(java.io.InputStream) IOException(java.io.IOException) BufferedSource(okio.BufferedSource)

Aggregations

GzipSource (okio.GzipSource)7 Buffer (okio.Buffer)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 BufferedSource (okio.BufferedSource)3 Test (org.junit.Test)3 Request (okhttp3.Request)2 Response (okhttp3.Response)2 AuthFailureError (com.android.volley.AuthFailureError)1 NetworkError (com.android.volley.NetworkError)1 NetworkResponse (com.android.volley.NetworkResponse)1 NoConnectionError (com.android.volley.NoConnectionError)1 ServerError (com.android.volley.ServerError)1 TimeoutError (com.android.volley.TimeoutError)1 Response (com.squareup.okhttp.Response)1 MalformedURLException (java.net.MalformedURLException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Cookie (okhttp3.Cookie)1