日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java inflaterinputstream_java.util.zip.InflaterInputStream.available()方法示例

發(fā)布時(shí)間:2025/3/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java inflaterinputstream_java.util.zip.InflaterInputStream.available()方法示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

java.util.zip.InflaterInputStream.available()方法在達(dá)到文件結(jié)尾(EOF)后返回0,否則返回1。

聲明

以下是java.util.zip.InflaterInputStream.available()方法的聲明。

public int available()

throws IOException

返回值

在到達(dá)底層輸入流結(jié)束后返回0,否則始終返回1。

異常

IOException - 如果發(fā)生I/O錯(cuò)誤或者此流已關(guān)閉。

示例

以下示例顯示了java.util.zip.InflaterInputStream.available()方法的用法。

package com.yiibai;

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.util.zip.DataFormatException;

import java.util.zip.Deflater;

import java.util.zip.InflaterInputStream;

public class InflaterInputStreamDemo {

public static void main(String[] args) throws DataFormatException, IOException {

String message = "Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;"

+"Welcome to Yiibai.com;";

System.out.println("Original Message length : " + message.length());

byte[] input = message.getBytes("UTF-8");

int length = message.length();

// Compress the bytes

byte[] output = new byte[1024];

Deflater deflater = new Deflater();

deflater.setInput(input);

deflater.finish();

int compressedDataLength = deflater.deflate(output,0 , output.length, Deflater.NO_FLUSH);

System.out.println("Total uncompressed bytes input :" + deflater.getTotalIn());

System.out.println("Compressed Message Checksum :" + deflater.getAdler());

deflater.finished();

System.out.println("Compressed Message length : " + compressedDataLength);

ByteArrayInputStream bin = new ByteArrayInputStream(output);

InflaterInputStream inflaterInputStream = new InflaterInputStream(bin);

byte[] result = new byte[1024];

ByteArrayOutputStream buffer = new ByteArrayOutputStream();

while(inflaterInputStream.available() != 0){

buffer.write(inflaterInputStream.read());

}

inflaterInputStream.close();

// Decode the bytes into a String

String message1 = new String(buffer.toByteArray(),0, length,"UTF-8");

System.out.println(message.equals(message1));

}

}

執(zhí)行上面示例代碼,得到以下結(jié)果 -

Original Message length : 300

Total uncompressed bytes input :300

Compressed Message Checksum :368538129

Compressed Message length : 42

true

¥ 我要打賞

糾錯(cuò)/補(bǔ)充

收藏

加QQ群啦,易百教程官方技術(shù)學(xué)習(xí)群

注意:建議每個(gè)人選自己的技術(shù)方向加群,同一個(gè)QQ最多限加 3 個(gè)群。

總結(jié)

以上是生活随笔為你收集整理的java inflaterinputstream_java.util.zip.InflaterInputStream.available()方法示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。