TarArchiveInputStream 是缓冲输入流还是非缓冲输入流?
Is TarArchiveInputStream buffered or unbuffered inputstream?
是TarArchiveInputStreambuffered
还是unbuffered
inputstream
?
InputStream inputStream = new TarArchiveInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(file))));
inputStream
这个对象是否将整个文件内部存储到堆内存中?或者它只是一个指向文件的指针,什么都不存储到内存中?
基于commons-compress.jar ver 1.4
、
的源代码
What happens when we create an instance of TarArchiveInputStream?
除了其他初始化之外,创建的重要对象是 TarBuffer 对象的实例,它内部有一个 byte[] blockBuffer
,其默认大小为 (DEFAULT_RCDSIZE * 20)
即.. 512*20 = 10KB。
此 TarBuffer
对象实际上执行读取操作并将数据从基础 tar
文件作为 readblock() method gets called internally as we invoke TarArchiveInputStream.read(..)
写入此 blockBuffer
Does the object of TarArchiveInputStream store the whole entire file internally into the heap memory?
没有。事实上,一般来说,只要我们调用一个 inputStream
的 read 方法,如果流被缓冲,就会尝试从应用程序缓冲区中获取数据。如果请求的数据存在,它会从缓冲区中为它提供服务。如果不是,它会通知 OS(通过陷阱)从 OS 文件 cache/disk 中读取数据并将其复制到其缓冲区中。 (内存映射文件有点不同,不需要复制到其中,但我们不会在讨论中混用)。
即使在 TarArchiveInputStream
的情况下也是如此。当我们在 TarArchiveInputStream
上调用 read
方法时,它委托给内部 inputStream
并且上面的相同流程可以可视化。
Or is it just a pointer to a file and stores nothing into the memory?
在创建 TarArchiveInputStream
时,我们传递一个 inputStream
作为参数,这个 inputStream
实际上是一个指针(据我所知,它在 inode 中*-nix OS 中的数字并指向实际的 inode 结构)到文件。
如前所述,它确实将内容存储到内存中,但不是整个文件。读入内存的数据量取决于在 TarArchiveInputStream
.
上调用 read(...)
方法时传递给 byte[]
的大小
此外,如果有帮助,这是我用来查看如何使用 TarArchiveInputStream
阅读条目的 link。
是TarArchiveInputStreambuffered
还是unbuffered
inputstream
?
InputStream inputStream = new TarArchiveInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(file))));
inputStream
这个对象是否将整个文件内部存储到堆内存中?或者它只是一个指向文件的指针,什么都不存储到内存中?
基于commons-compress.jar ver 1.4
、
What happens when we create an instance of TarArchiveInputStream?
除了其他初始化之外,创建的重要对象是 TarBuffer 对象的实例,它内部有一个 byte[] blockBuffer
,其默认大小为 (DEFAULT_RCDSIZE * 20)
即.. 512*20 = 10KB。
此 TarBuffer
对象实际上执行读取操作并将数据从基础 tar
文件作为 readblock() method gets called internally as we invoke TarArchiveInputStream.read(..)
blockBuffer
Does the object of TarArchiveInputStream store the whole entire file internally into the heap memory?
没有。事实上,一般来说,只要我们调用一个 inputStream
的 read 方法,如果流被缓冲,就会尝试从应用程序缓冲区中获取数据。如果请求的数据存在,它会从缓冲区中为它提供服务。如果不是,它会通知 OS(通过陷阱)从 OS 文件 cache/disk 中读取数据并将其复制到其缓冲区中。 (内存映射文件有点不同,不需要复制到其中,但我们不会在讨论中混用)。
即使在 TarArchiveInputStream
的情况下也是如此。当我们在 TarArchiveInputStream
上调用 read
方法时,它委托给内部 inputStream
并且上面的相同流程可以可视化。
Or is it just a pointer to a file and stores nothing into the memory?
在创建 TarArchiveInputStream
时,我们传递一个 inputStream
作为参数,这个 inputStream
实际上是一个指针(据我所知,它在 inode 中*-nix OS 中的数字并指向实际的 inode 结构)到文件。
如前所述,它确实将内容存储到内存中,但不是整个文件。读入内存的数据量取决于在 TarArchiveInputStream
.
read(...)
方法时传递给 byte[]
的大小
此外,如果有帮助,这是我用来查看如何使用 TarArchiveInputStream
阅读条目的 link。