本文整理匯總了Java中java.util.zip.GZIPInputStream.skip方法的典型用法代碼示例。如果您正苦於以下問題:Java GZIPInputStream.skip方法的具體用法?Java GZIPInputStream.skip怎麽用?Java GZIPInputStream.skip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.zip.GZIPInputStream
的用法示例。
在下文中一共展示了GZIPInputStream.skip方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTest
import java.util.zip.GZIPInputStream; //導入方法依賴的package包/類
private static void doTest(final boolean appendGarbage,
final boolean limitGISBuff)
throws Throwable {
byte[] buf;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos)) {
final byte[] xbuf = { 'x' };
zos.putNextEntry(new ZipEntry("a.gz"));
GZIPOutputStream gos1 = new GZIPOutputStream(zos);
gos1.write(xbuf);
gos1.finish();
if (appendGarbage)
zos.write(xbuf);
zos.closeEntry();
zos.putNextEntry(new ZipEntry("b.gz"));
GZIPOutputStream gos2 = new GZIPOutputStream(zos);
gos2.write(xbuf);
gos2.finish();
zos.closeEntry();
zos.flush();
buf = baos.toByteArray();
}
try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
ZipInputStream zis = new ZipInputStream(bais)) {
zis.getNextEntry();
GZIPInputStream gis1 = limitGISBuff ?
new GZIPInputStream(zis, 4) :
new GZIPInputStream(zis);
// try to read more than the entry has
gis1.skip(2);
try {
zis.getNextEntry();
} catch (IOException e) {
throw new RuntimeException("ZIP stream was prematurely closed", e);
}
}
}