InputStream fileStream = new FileInputStream(filename); InputStream gzipStream = new GZIPInputStream(fileStream); Reader decoder = new InputStreamReader(gzipStream, encoding); BufferedReader buffered = new BufferedReader(decoder);
public static Map<String, Object> fromCompressedJsonConf(byte[] serialized) { try { ByteArrayInputStream bis = new ByteArrayInputStream(serialized); InputStreamReader in = new InputStreamReader(new GZIPInputStream(bis)); Object ret = JSONValue.parseWithException(in); in.close(); return (Map<String, Object>) ret; } catch (IOException | ParseException e) { throw new RuntimeException(e); } }
public static byte[] gunzip(byte[] data) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(data); GZIPInputStream in = new GZIPInputStream(bis); byte[] buffer = new byte[1024]; int len = 0; while ((len = in.read(buffer)) >= 0) { bos.write(buffer, 0, len); } in.close(); bos.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
ByteArrayInputStream bais = new ByteArrayInputStream(responseBytes); GZIPInputStream gzis = new GZIPInputStream(bais); InputStreamReader reader = new InputStreamReader(gzis); BufferedReader in = new BufferedReader(reader); String readed; while ((readed = in.readLine()) != null) { System.out.println(readed); }
protected Object loadObject(String path) throws IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream(new BufferedInputStream( new GZIPInputStream(new FileInputStream(path)))); Object obj = in.readObject(); in.close(); return obj; }
/** * Creates a new <code>Reader</code> that reads from the given log file with the given name. * Invoking this constructor will start this reader thread. * * @param patterns java regular expressions that an entry must match one or more of */ public NonThreadedReader(final InputStream logFile, final String logFileName, final ThreadGroup group, final boolean tabOut, final boolean suppressBlanks, final List<Pattern> patterns) { if (logFileName.endsWith(".gz")) { try { this.logFile = new BufferedReader(new InputStreamReader(new GZIPInputStream(logFile))); } catch (IOException e) { System.err.println(logFileName + " does not appear to be in gzip format"); this.logFile = new BufferedReader(new InputStreamReader(logFile)); } } else { this.logFile = new BufferedReader(new InputStreamReader(logFile)); } this.logFileName = logFileName; this.patterns = patterns; parser = new LogFileParser(this.logFileName, this.logFile, tabOut, suppressBlanks); }
private String pageFile(String path, boolean isZipFile, long fileLength, Integer start, Integer readLength) throws IOException, InvalidRequestException { try (InputStream input = isZipFile ? new GZIPInputStream(new FileInputStream(path)) : new FileInputStream(path); ByteArrayOutputStream output = new ByteArrayOutputStream()) { if (start >= fileLength) { throw new InvalidRequestException("Cannot start past the end of the file"); } if (start > 0) { StreamUtil.skipBytes(input, start); } byte[] buffer = new byte[1024]; while (output.size() < readLength) { int size = input.read(buffer, 0, Math.min(1024, readLength - output.size())); if (size > 0) { output.write(buffer, 0, size); } else { break; } } numPageRead.mark(); return output.toString(); } catch (FileNotFoundException e) { numFileOpenExceptions.mark(); throw e; } catch (IOException e) { numFileReadExceptions.mark(); throw e; } }
new FileInputStream(file))) { Reader in = compressed ? new InputStreamReader(new GZIPInputStream( iss)) : new InputStreamReader(iss); dump(out, in); return true;
public static byte[] unZip(byte[] data) throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(data); java.util.zip.GZIPInputStream gin = new GZIPInputStream(in); data = FileUtil.readAll(gin); gin.close(); return data; } }
private String loadJSON(String name) { try { FileInputStream fis = new FileInputStream(new File(dataRoot, name + ".json.gz")); ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamUtil.copy(new GZIPInputStream(fis), out); String json = out.toString("UTF-8"); fis.close(); return json; } catch (IOException io) { throw new RuntimeException(io); } } }
@Override public <T> T deserialize(byte[] bytes, Class<T> clazz) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); GZIPInputStream gis = new GZIPInputStream(bis); ObjectInputStream ois = new ObjectInputStream(gis); Object ret = ois.readObject(); ois.close(); return (T) ret; } catch (IOException | ClassNotFoundException ioe) { throw new RuntimeException(ioe); } } }
public static byte[] tryDecompress(InputStream raw) throws Exception { try { GZIPInputStream gis = new GZIPInputStream(raw); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(gis, out); return out.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * Unzips GZip-ed body content, removes the content-encoding header * and sets the new content-length value. */ public HttpResponse unzip() { String contentEncoding = contentEncoding(); if (contentEncoding != null && contentEncoding().equals("gzip")) { if (body != null) { headerRemove(HEADER_CONTENT_ENCODING); try { ByteArrayInputStream in = new ByteArrayInputStream(body.getBytes(StringPool.ISO_8859_1)); GZIPInputStream gzipInputStream = new GZIPInputStream(in); ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamUtil.copy(gzipInputStream, out); body(out.toString(StringPool.ISO_8859_1)); } catch (IOException ioex) { throw new HttpException(ioex); } } } return this; }
String body = null; String charset = "UTF-8"; // You should determine it based on response header. try ( InputStream gzippedResponse = response.getInputStream(); InputStream ungzippedResponse = new GZIPInputStream(gzippedResponse); Reader reader = new InputStreamReader(ungzippedResponse, charset); Writer writer = new StringWriter(); ) { char[] buffer = new char[10240]; for (int length = 0; (length = reader.read(buffer)) > 0;) { writer.write(buffer, 0, length); } body = writer.toString(); } // ...
public static byte[] unGzipBytes(final byte[] bytes) throws IOException { final ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes); final GZIPInputStream gzipInputStream = new GZIPInputStream(byteInputStream); final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); IOUtils.copy(gzipInputStream, byteOutputStream); return byteOutputStream.toByteArray(); }
private BufferedReader createNextReader() throws IOException { if (!files.hasNext()) { return null; } File file = files.next(); FileInputStream fileInputStream = new FileInputStream(file); InputStream in = isGZipped(file) ? new GZIPInputStream(fileInputStream) : fileInputStream; return new BufferedReader(new InputStreamReader(in)); }
public static String gzipToString(byte[] gzip) throws IOException { GZIPInputStream gzipIs = new GZIPInputStream(new ByteArrayInputStream(gzip)); BufferedReader br = new BufferedReader(new InputStreamReader(gzipIs, "UTF-8")); StringBuilder sb = new StringBuilder(); String s; while ((s = br.readLine()) != null) { sb.append(s); } br.close(); return sb.toString(); }
public static Object loadObject(String path) throws IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream(new BufferedInputStream( new GZIPInputStream(new FileInputStream(path)))); Object obj = in.readObject(); in.close(); return obj; }
/** * Creates a new <code>Reader</code> that reads from the given log file with the given name. * Invoking this constructor will start this reader thread. The InputStream is closed at the * end of processing. */ public ThreadedReader(final InputStream logFile, final String logFileName, final ThreadGroup group, final boolean tabOut, final boolean suppressBlanks, final List<Pattern> patterns) { super(group, "Log File Reader"); if (logFileName.endsWith(".gz")) { try { this.logFile = new BufferedReader(new InputStreamReader(new GZIPInputStream(logFile))); } catch (IOException e) { System.err.println(logFileName + " does not appear to be in gzip format"); this.logFile = new BufferedReader(new InputStreamReader(logFile)); } } else { this.logFile = new BufferedReader(new InputStreamReader(logFile)); } this.logFileName = logFileName; queue = new LinkedBlockingQueue(QUEUE_CAPACITY); this.suppressBlanks = suppressBlanks; this.tabOut = tabOut; this.patterns = patterns; start(); }
new FileInputStream(file))) { Reader in = compressed ? new InputStreamReader(new GZIPInputStream( iss)) : new InputStreamReader(iss); dumpXref(out, in, contextPath); return true;