InputStream fileStream = new FileInputStream(filename); InputStream gzipStream = new GZIPInputStream(fileStream); Reader decoder = new InputStreamReader(gzipStream, encoding); BufferedReader buffered = new BufferedReader(decoder);
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); } }
@Override public Void call() throws IOException { GZIPInputStream in = new GZIPInputStream(mIn); try { Util.copy(in, mOut, new byte[1024]); } finally { in.close(); mOut.close(); } return null; } }
public static void gunzip(File source, File dest, boolean deleteSource) throws IOException { byte[] buffer = new byte[2^20]; FileOutputStream out = new FileOutputStream(dest); GZIPInputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(source))); int l; while ((l = in.read(buffer)) > 0) out.write(buffer, 0, l); in.close(); out.close(); if (deleteSource && dest.exists()) source.delete(); }
ips = new BufferedInputStream(new FileInputStream(file), 50000); } catch (FileNotFoundException e) { throw new RuntimeException(e); ips.mark(10); if (ips.read(header) < 0) throw new IllegalArgumentException("Input file is not of valid type " + file.getPath()); ips.reset(); return new GZIPInputStream(ips, 50000); } else if (header[0] == 0 && header[1] == 0 && header[2] == 0 && header[4] == 10 && header[5] == 9
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; }
/** * Decompress gzip archive. */ public static File ungzip(File file) throws IOException { String outFileName = FileNameUtil.removeExtension(file.getAbsolutePath()); File out = new File(outFileName); out.createNewFile(); FileOutputStream fos = new FileOutputStream(out); GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file)); try { StreamUtil.copy(gzis, fos); } finally { StreamUtil.close(fos); StreamUtil.close(gzis); } return out; }
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; } }
try (InputStream iss = new BufferedInputStream( new FileInputStream(file))) { Reader in = compressed ? new InputStreamReader(new GZIPInputStream( iss)) : new InputStreamReader(iss); dump(out, in); return true;
input = input + "/flow.xml.gz"; InputStream fileStream = new FileInputStream(input); InputStream gzipStream = new GZIPInputStream(fileStream); System.out.println("Max Flowfile Queue Size=" + maxQueueSize + "\nMin Flowfile Queue Size=" + minQueueSize + "\nAvg Flowfile Queue Size=" + new BigDecimal(totalQueueSize).divide(new BigDecimal(numberOfConnections), DIVIDE_SCALE, RoundingMode.HALF_UP)); gzipStream.close(); fileStream.close(); } catch (Exception e) { e.printStackTrace();
private static void unTarUsingJava(File inFile, File untarDir, boolean gzipped, boolean symlinksDisabled) throws IOException { final String base = untarDir.getCanonicalPath(); LOG.trace("java untar {} to {}", inFile, base); InputStream inputStream = null; try { if (gzipped) { inputStream = new BufferedInputStream(new GZIPInputStream( new FileInputStream(inFile))); } else { inputStream = new BufferedInputStream(new FileInputStream(inFile)); } try (TarArchiveInputStream tis = new TarArchiveInputStream(inputStream)) { for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null; ) { unpackEntries(tis, entry, untarDir, base, symlinksDisabled); entry = tis.getNextTarEntry(); } } } finally { if (inputStream != null) { inputStream.close(); } } }
@Test void testStuck() throws IOException { File file = new File(testDataRoot, "stuck.html.gz"); InputStream in = new GZIPInputStream(new FileInputStream(file)); ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamUtil.copy(in, out); in.close(); Jerry.JerryParser jerryParser = new Jerry.JerryParser(); // LagartoDOMBuilder lagartoDOMBuilder = (LagartoDOMBuilder) jerryParser.getDOMBuilder(); // lagartoDOMBuilder.setParsingErrorLogLevelName("ERROR"); Jerry doc = jerryParser.parse(out.toString("UTF-8")); // parse try { doc.$("a").each(($this, index) -> { assertEquals("Go to Database Directory", $this.html().trim()); return false; }); } catch (StackOverflowError stackOverflowError) { fail("stack overflow!"); } } }
progressMax = 50; GZIPInputStream gzipInputStream = new GZIPInputStream( new BufferedInputStream(new FileInputStream(zippedFile))); OutputStream outputStream = new FileOutputStream(outFilePath); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( outputStream); byte[] data = new byte[BUFFER]; int len; while ((len = gzipInputStream.read(data, 0, BUFFER)) > 0) { bufferedOutputStream.write(data, 0, len); unzippedBytes += len; gzipInputStream.close(); bufferedOutputStream.flush(); bufferedOutputStream.close();
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); } } }
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); } }
final InputStream is = new FileInputStream(inputFile); final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is); TarArchiveEntry entry = null; final OutputStream outputFileStream = new FileOutputStream(outputFile); IOUtils.copy(debInputStream, outputFileStream); outputFileStream.close(); final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile)); final FileOutputStream out = new FileOutputStream(outputFile); in.close(); out.close();
log.info("Reading initial LOP weights from file " + flags.initialLopWeights + " ..."); List<double[]> listOfWeights = new ArrayList<>(numLopExpert); for (String line; (line = br.readLine()) != null; ) { line = line.trim(); String[] parts = line.split("\t"); } else { log.info("Reading initial LOP scales from file " + flags.initialLopScales); try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream( flags.initialLopScales))))) { initialScales = ConvertByteArray.readDoubleArr(dis);
if (log.getName().endsWith(".gz")) { reader = new LineNumberReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(log)))); } else { reader = new LineNumberReader(new FileReader(log));
/** Return a reader for the specified xref file. */ private static Reader getXrefReader( File basedir, String path, boolean compressed) throws IOException { /* * For backward compatibility, read the OpenGrok-produced document * using the system default charset. */ if (compressed) { return new BufferedReader(IOUtils.createBOMStrippedReader( new GZIPInputStream(new FileInputStream(new File(basedir, TandemPath.join(path, ".gz")))))); } else { return new BufferedReader(IOUtils.createBOMStrippedReader( new FileInputStream(new File(basedir, path)))); } }
/** * 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); }