本文整理了Java中java.util.zip.GZIPInputStream
类的一些代码示例,展示了GZIPInputStream
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GZIPInputStream
类的具体详情如下:
包路径:java.util.zip.GZIPInputStream
类名称:GZIPInputStream
[英]The GZIPInputStream class is used to read data stored in the GZIP format, reading and decompressing GZIP data from the underlying stream into its buffer.
Using GZIPInputStream is easier than ZipInputStreambecause GZIP is only for compression, and is not a container for multiple files. This code decompresses the data from a GZIP stream, similar to the gunzip(1) utility.
InputStream is = ...
GZIPInputStream zis = new GZIPInputStream(new BufferedInputStream(is));
try {
// Reading from 'zis' gets you the uncompressed bytes...
processStream(zis);
} finally {
zis.close();
}
[中]GZIPInputStream类用于读取以GZIP格式存储的数据,将GZIP数据从底层流读取并解压缩到其缓冲区中。
####范例
使用GZIPInputStream比使用ZipInputStream更容易,因为GZIP仅用于压缩,而不是多个文件的容器。这段代码从GZIP流解压数据,类似于gunzip(1)实用程序。
InputStream is = ...
GZIPInputStream zis = new GZIPInputStream(new BufferedInputStream(is));
try {
// Reading from 'zis' gets you the uncompressed bytes...
processStream(zis);
} finally {
zis.close();
}
代码示例来源:origin: stackoverflow.com
InputStream fileStream = new FileInputStream(filename);
InputStream gzipStream = new GZIPInputStream(fileStream);
Reader decoder = new InputStreamReader(gzipStream, encoding);
BufferedReader buffered = new BufferedReader(decoder);
代码示例来源:origin: apache/storm
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);
}
}
代码示例来源:origin: facebook/stetho
@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;
}
}
代码示例来源:origin: loklak/loklak_server
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();
}
代码示例来源:origin: graphhopper/graphhopper
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
代码示例来源:origin: FudanNLP/fnlp
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;
}
代码示例来源:origin: redisson/redisson
/**
* 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;
}
代码示例来源:origin: apache/storm
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;
}
}
代码示例来源:origin: oracle/opengrok
try (InputStream iss = new BufferedInputStream(
new FileInputStream(file))) {
Reader in = compressed ? new InputStreamReader(new GZIPInputStream(
iss)) : new InputStreamReader(iss);
dump(out, in);
return true;
代码示例来源:origin: apache/nifi
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();
代码示例来源:origin: apache/storm
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();
}
}
}
代码示例来源:origin: oblac/jodd
@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!");
}
}
}
代码示例来源:origin: rmtheis/android-ocr
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();
代码示例来源:origin: oblac/jodd
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);
}
}
}
代码示例来源:origin: apache/storm
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);
}
}
代码示例来源:origin: stackoverflow.com
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();
代码示例来源:origin: stanfordnlp/CoreNLP
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);
代码示例来源:origin: apache/geode
if (log.getName().endsWith(".gz")) {
reader = new LineNumberReader(
new InputStreamReader(new GZIPInputStream(new FileInputStream(log))));
} else {
reader = new LineNumberReader(new FileReader(log));
代码示例来源:origin: oracle/opengrok
/** 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))));
}
}
代码示例来源:origin: apache/geode
/**
* 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);
}
内容来源于网络,如有侵权,请联系作者删除!