本文整理了Java中java.util.zip.GZIPInputStream.<init>()
方法的一些代码示例,展示了GZIPInputStream.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GZIPInputStream.<init>()
方法的具体详情如下:
包路径:java.util.zip.GZIPInputStream
类名称:GZIPInputStream
方法名:<init>
[英]Construct a GZIPInputStream to read from GZIP data from the underlying stream.
[中]构造一个GZIPInputStream,从底层流中读取GZIP数据。
代码示例来源: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 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: 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: stackoverflow.com
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);
}
代码示例来源:origin: FudanNLP/fnlp
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;
}
代码示例来源: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);
}
代码示例来源: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
new FileInputStream(file))) {
Reader in = compressed ? new InputStreamReader(new GZIPInputStream(
iss)) : new InputStreamReader(iss);
dump(out, in);
return true;
代码示例来源:origin: scouter-project/scouter
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;
}
}
代码示例来源: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: alibaba/jstorm
@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);
}
}
}
代码示例来源:origin: alibaba/nacos
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;
}
代码示例来源:origin: oblac/jodd
/**
* 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;
}
代码示例来源:origin: stackoverflow.com
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();
}
// ...
代码示例来源:origin: azkaban/azkaban
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();
}
代码示例来源:origin: prestodb/presto
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));
}
代码示例来源:origin: osmandapp/Osmand
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();
}
代码示例来源: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: 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. 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();
}
代码示例来源:origin: oracle/opengrok
new FileInputStream(file))) {
Reader in = compressed ? new InputStreamReader(new GZIPInputStream(
iss)) : new InputStreamReader(iss);
dumpXref(out, in, contextPath);
return true;
内容来源于网络,如有侵权,请联系作者删除!