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));
}
}
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();
}
Aggregations