Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java InputStream和字节数组生成器?_Java - Fatal编程技术网

Java InputStream和字节数组生成器?

Java InputStream和字节数组生成器?,java,Java,我有一个类,它将从zip文件中获取固定大小的字节数组缓冲区。有没有办法把它连接到ZipInputStream上?有点像: public class MyByteArrayProducer { public boolean hasMoreData(); public void getNextChunk(byte[] buffer); } ZipInputStream类需要从中读取InputStream,但我必须使用上面的类 谢谢基于字节数组创建一个,然后将此流传递给ZipInpu

我有一个类,它将从zip文件中获取固定大小的字节数组缓冲区。有没有办法把它连接到ZipInputStream上?有点像:

public class MyByteArrayProducer {
    public boolean hasMoreData();
    public void getNextChunk(byte[] buffer);
}
ZipInputStream类需要从中读取InputStream,但我必须使用上面的类

谢谢

基于字节数组创建一个,然后将此流传递给ZipInputStream构造函数

--编辑--

如果字节数组太大,无法完全保存在内存中,则可以使用管道流来允许在小数据块到达时对其进行处理:

// Write byte arrays to this stream in the producer thread
PipedOutputStream os = new PipedOutputStream(); 

PipedInputStream in = new PipedInputStream(os);
// Read from this stream in the consumer thread
ZipInputStream zis = new ZipInputStream(in); 

请看。我可能误解了-但这不需要将完整字节数组传递给ByteArrayInputStream实例吗?如果是的话,我不能这样做,因为它是1.5gb。