本文整理匯總了Java中java.util.zip.GZIPInputStream.available方法的典型用法代碼示例。如果您正苦於以下問題:Java GZIPInputStream.available方法的具體用法?Java GZIPInputStream.available怎麽用?Java GZIPInputStream.available使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.zip.GZIPInputStream
的用法示例。
在下文中一共展示了GZIPInputStream.available方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decompress
import java.util.zip.GZIPInputStream; //導入方法依賴的package包/類
/**
* Decompresses a GZip'd byte array.
*
* @param compressedBytes
* The compressed byte array.
*
* @return
* The decompressed byte array.
*
* @throws IOException
* If an I/O error has occurred.
*/
private static byte[] decompress(final byte[] compressedBytes) throws IOException {
final ByteArrayInputStream byteInputStream = new ByteArrayInputStream(compressedBytes);
final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(compressedBytes.length);
final GZIPInputStream gzipInputStream = new GZIPInputStream(byteInputStream);
byte[] buffer = new byte[1024];
while (gzipInputStream.available() > 0) {
final int count = gzipInputStream.read(buffer, 0, 1024);
if (count > 0) {
byteOutputStream.write(buffer, 0, count);
}
}
gzipInputStream.close();
byteOutputStream.close();
byteInputStream.close();
return byteOutputStream.toByteArray();
}