本文介绍了如何将ZipInputStream转换为InputStream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有将ZipInputSream转换为byte []的代码,但我不知道如何将其转换为inputstream.
I have code, where ZipInputSream is converted to byte[], but I don't know how I can convert that to inputstream.
private void convertStream(String encoding, ZipInputStream in) throws IOException,
UnsupportedEncodingException
{
final int BUFFER = 1;
@SuppressWarnings("unused")
int count = 0;
byte data[] = new byte[BUFFER];
while ((count = in.read(data, 0, BUFFER)) != -1)
{
// How can I convert data to InputStream here ?
}
}
推荐答案
这是我解决此问题的方法.现在,我可以将单个文件从ZipInputStream作为InputStream获取到内存中.
Here is how I solved this problem. Now I can get single files from ZipInputStream to memory as InputStream.
private InputStream convertZipInputStreamToInputStream(ZipInputStream in, ZipEntry entry, String encoding) throws IOException
{
final int BUFFER = 2048;
int count = 0;
byte data[] = new byte[BUFFER];
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((count = in.read(data, 0, BUFFER)) != -1) {
out.write(data);
}
InputStream is = new ByteArrayInputStream(out.toByteArray());
return is;
}
这篇关于如何将ZipInputStream转换为InputStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!