List of usage examples for java.util.zip GZIPInputStream GZIPInputStream
public GZIPInputStream(InputStream in) throws IOException
From source file:it.restrung.rest.utils.IOUtils.java
/** * Loads a serialized object from a file * * @param file the file where the object was serialized * @return the serialized object in its real in memory object representation *///from w w w. j a va 2 s. co m @SuppressWarnings("unchecked") static public <T> T loadSerializableObjectFromDisk(File file) { T result = null; if (file.exists()) { try { FileInputStream fis = new FileInputStream(file); GZIPInputStream gzis = new GZIPInputStream(fis); ObjectInputStream in = new ObjectInputStream(gzis); result = (T) in.readObject(); in.close(); } catch (FileNotFoundException e) { Log.d(IOUtils.class.getName(), "Error, file not found for load serializable object from disk"); throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return result; }
From source file:edu.umd.umiacs.clip.tools.io.GZIPFiles.java
protected static Stream<String> lines(Path path) throws IOException { BufferedReader br = null;//w ww.java 2 s.c o m try { br = new BufferedReader(new InputStreamReader( new GZIPInputStream(new BufferedInputStream(newInputStream(path), BUFFER_SIZE)), UTF_8.newDecoder().onMalformedInput(IGNORE))); return br.lines().onClose(asUncheckedRunnable(br)); } catch (IOException e) { try { br.close(); } catch (Exception ex) { try { e.addSuppressed(ex); } catch (Throwable ignore) { } } throw e; } }
From source file:examples.utils.CifarReader.java
public static void downloadAndExtract() { if (new File("data", TEST_DATA_FILE).exists() == false) { try {/*from w w w. j a v a 2s. c om*/ if (new File("data", ARCHIVE_BINARY_FILE).exists() == false) { URL website = new URL("http://www.cs.toronto.edu/~kriz/" + ARCHIVE_BINARY_FILE); FileOutputStream fos = new FileOutputStream("data/" + ARCHIVE_BINARY_FILE); fos.getChannel().transferFrom(Channels.newChannel(website.openStream()), 0, Long.MAX_VALUE); fos.close(); } TarArchiveInputStream tar = new TarArchiveInputStream( new GZIPInputStream(new FileInputStream("data/" + ARCHIVE_BINARY_FILE))); TarArchiveEntry entry = null; while ((entry = tar.getNextTarEntry()) != null) { if (entry.isDirectory()) { new File("data", entry.getName()).mkdirs(); } else { byte data[] = new byte[2048]; int count; BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(new File("data/", entry.getName())), 2048); while ((count = tar.read(data, 0, 2048)) != -1) { bos.write(data, 0, count); } bos.close(); } } tar.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static String[] getUrlInfos(String urlAsString, int timeout) { try {//from w w w . j ava 2 s. c om URL url = new URL(urlAsString); //using proxy may increase latency HttpURLConnection hConn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY); hConn.setRequestProperty("User-Agent", "Mozilla/5.0 Gecko/20100915 Firefox/3.6.10"); // on android we got problems because of this // so disable that for now // hConn.setRequestProperty("Accept-Encoding", "gzip, deflate"); hConn.setConnectTimeout(timeout); hConn.setReadTimeout(timeout); // default length of bufferedinputstream is 8k byte[] arr = new byte[K4]; InputStream is = hConn.getInputStream(); if ("gzip".equals(hConn.getContentEncoding())) is = new GZIPInputStream(is); BufferedInputStream in = new BufferedInputStream(is, arr.length); in.read(arr); return getUrlInfosFromText(arr, hConn.getContentType()); } catch (Exception ex) { } return new String[] { "", "" }; }
From source file:Main.java
public static Reader getUri(URL url) throws IOException { //Log.d(TAG, "getUri: " + url.toString()); boolean useGzip = false; HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(30 * 1000);/* ww w .j a v a 2 s.co m*/ conn.setRequestProperty("Accept-Encoding", "gzip"); conn.connect(); InputStream in = conn.getInputStream(); final Map<String, List<String>> headers = conn.getHeaderFields(); // This is a map, but we can't assume the key we're looking for // is in normal casing. So it's really not a good map, is it? final Set<Map.Entry<String, List<String>>> set = headers.entrySet(); for (Iterator<Map.Entry<String, List<String>>> i = set.iterator(); i.hasNext();) { Map.Entry<String, List<String>> entry = i.next(); if ("Content-Encoding".equalsIgnoreCase(entry.getKey())) { for (Iterator<String> j = entry.getValue().iterator(); j.hasNext();) { String str = j.next(); if (str.equalsIgnoreCase("gzip")) { useGzip = true; break; } } // Break out of outer loop. if (useGzip) { break; } } } if (useGzip) { return new BufferedReader(new InputStreamReader(new GZIPInputStream(in)), 8 * 1024); } else { return new BufferedReader(new InputStreamReader(in), 8 * 1024); } }
From source file:ch.ledcom.jpreseed.InitrdRepackerTest.java
private static CpioArchiveInputStream gzippedCpio(ByteArrayOutputStream stream) throws IOException { return new CpioArchiveInputStream(new GZIPInputStream(new ByteArrayInputStream(stream.toByteArray()))); }
From source file:com.dwdesign.tweetings.util.httpclient.ApacheHttpClientHttpResponseImpl.java
ApacheHttpClientHttpResponseImpl(final HttpResponse res, final HttpClientConfiguration conf) throws IOException { super(conf);// w ww . j av a2 s.c om this.res = res; is = res.getEntity().getContent(); statusCode = res.getStatusLine().getStatusCode(); if (is != null && "gzip".equals(getResponseHeader("Content-Encoding"))) { // the response is gzipped is = new GZIPInputStream(is); } }
From source file:com.nimble.http.client.GzipClientHttpResponse.java
public InputStream getBody() throws IOException { InputStream errorStream = this.connection.getErrorStream(); return (errorStream != null ? errorStream : StringUtils.hasLength(this.connection.getContentEncoding()) && this.connection .getContentEncoding().equalsIgnoreCase(GzipClientHttpRequest.ENCODING_GZIP) ? new GZIPInputStream(this.connection.getInputStream()) : this.connection.getInputStream()); }
From source file:uk.ac.ebi.eva.pipeline.io.GzipLazyResource.java
@Override public InputStream getInputStream() throws IOException { return new GZIPInputStream(super.getInputStream()); }
From source file:de.jetwick.util.Translate.java
public static String download(String urlAsString) { try {/* ww w . ja v a 2s. c o m*/ URL url = new URL(urlAsString); //using proxy may increase latency HttpURLConnection hConn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY); hConn.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"); hConn.addRequestProperty("Referer", "http://jetsli.de/crawler"); hConn.setConnectTimeout(2000); hConn.setReadTimeout(2000); InputStream is = hConn.getInputStream(); if ("gzip".equals(hConn.getContentEncoding())) is = new GZIPInputStream(is); return getInputStream(is); } catch (Exception ex) { return ""; } }