use of java.util.zip.GZIPInputStream in project okhttp by square.
the class URLConnectionTest method clientConfiguredGzipContentEncoding.
@Test
public void clientConfiguredGzipContentEncoding() throws Exception {
Buffer bodyBytes = gzip("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
server.enqueue(new MockResponse().setBody(bodyBytes).addHeader("Content-Encoding: gzip"));
URLConnection connection = urlFactory.open(server.url("/").url());
connection.addRequestProperty("Accept-Encoding", "gzip");
InputStream gunzippedIn = new GZIPInputStream(connection.getInputStream());
assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", readAscii(gunzippedIn, Integer.MAX_VALUE));
assertEquals(bodyBytes.size(), connection.getContentLength());
RecordedRequest request = server.takeRequest();
assertEquals("gzip", request.getHeader("Accept-Encoding"));
}
use of java.util.zip.GZIPInputStream in project okio by square.
the class LargeStreamsTest method gzipSink.
@Test
public void gzipSink() throws Exception {
Pipe pipe = new Pipe(1024 * 1024);
GzipSink gzipSink = new GzipSink(pipe.sink());
// Disable compression to speed up a slow test. Improved from 141s to 35s on one machine.
gzipSink.deflater().setLevel(Deflater.NO_COMPRESSION);
Future<Long> future = readAllAndCloseAsync(randomSource(FOUR_GIB_PLUS_ONE), gzipSink);
HashingSink hashingSink = HashingSink.sha256(Okio.blackhole());
GZIPInputStream gzipIn = new GZIPInputStream(Okio.buffer(pipe.source()).inputStream());
readAllAndClose(Okio.source(gzipIn), hashingSink);
assertEquals(FOUR_GIB_PLUS_ONE, (long) future.get());
assertEquals(SHA256_RANDOM_FOUR_GIB_PLUS_1, hashingSink.hash());
}
use of java.util.zip.GZIPInputStream in project CoreNLP by stanfordnlp.
the class GenericAnnotationSerializer method read.
@Override
public Pair<Annotation, InputStream> read(InputStream is) throws IOException, ClassNotFoundException, ClassCastException {
ObjectInputStream objectInput;
if (is instanceof ObjectInputStream) {
objectInput = (ObjectInputStream) is;
} else {
objectInput = new ObjectInputStream(compress ? new GZIPInputStream(is) : is);
}
Object annotation = objectInput.readObject();
if (annotation == null)
return null;
if (!(annotation instanceof Annotation)) {
throw new ClassCastException("ERROR: Serialized data does not contain an Annotation!");
}
return Pair.makePair((Annotation) annotation, (InputStream) objectInput);
}
use of java.util.zip.GZIPInputStream in project CoreNLP by stanfordnlp.
the class AbstractSequenceClassifier method loadClassifier.
/**
* Loads a classifier from the file, classpath resource, or URL specified by loadPath. If loadPath ends in
* .gz, uses a GZIPInputStream.
*/
public void loadClassifier(String loadPath, Properties props) throws ClassCastException, IOException, ClassNotFoundException {
InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(loadPath);
Timing t = new Timing();
loadClassifier(is, props);
is.close();
t.done(log, "Loading classifier from " + loadPath);
}
use of java.util.zip.GZIPInputStream in project CoreNLP by stanfordnlp.
the class AbstractSequenceClassifier method loadJarClassifier.
/**
* This function will load a classifier that is stored inside a jar file (if
* it is so stored). The classifier should be specified as its full path
* in a jar. If the classifier is not stored in the jar file or this is not run
* from inside a jar file, then this function will throw a RuntimeException.
*
* @param modelName
* The name of the model file. Iff it ends in .gz, then it is assumed
* to be gzip compressed.
* @param props
* A Properties object which can override certain properties in the
* serialized file, such as the DocumentReaderAndWriter. You can pass
* in {@code null} to override nothing.
*/
// todo [john bauer 2015]: This method may not be necessary. Perhaps use the IOUtils equivalents
public void loadJarClassifier(String modelName, Properties props) {
Timing t = new Timing();
try {
InputStream is = getClass().getResourceAsStream(modelName);
if (modelName.endsWith(".gz")) {
is = new GZIPInputStream(is);
}
is = new BufferedInputStream(is);
loadClassifier(is, props);
is.close();
t.done(log, "Loading CLASSPATH classifier " + modelName);
} catch (Exception e) {
String msg = "Error loading classifier from jar file (most likely you are not running this code from a jar file or the named classifier is not stored in the jar file)";
throw new RuntimeException(msg, e);
}
}
Aggregations