[jcifs] Ramdom Access File (Zip file partial read using CIFS)

Giampaolo Tomassoni Giampaolo at Tomassoni.biz
Tue Jul 14 05:07:22 MDT 2009


> -----Original Message-----
> From: jcifs-bounces at lists.samba.org [mailto:jcifs-
> bounces at lists.samba.org] On Behalf Of pedrofaundezgon at terra.es
> Sent: Tuesday, July 14, 2009 11:24 AM
> To: jcifs at lists.samba.org
> Subject: [jcifs] Ramdom Access File (Zip file partial read using CIFS)
> 
> I want to access the contents of a Zip file from a Java program.
> I know java.util.zip.ZipFile can only access local files.
> And I also know the default API exposed by jcifs is only java.io.
> InputStream API
> Is there an easy way to read a huge ZipFile over the network
> extracting only the file I am interested in the most efficient way
> possible?
> Is there a way to have jcifs expose a random access file interface
> (just like local file) and a way to have ZipFile consume it?

First, jcifs seems also define a jcifs.smb.SmbRandomAccessFile class.

However, I think you wouldn't need it. I would instead check if:

1) java.util.zip.ZipInputStream uses skip() on the InputStream passed in its constructor in order to position itself in the zip file;

2) the skip() method in jcifs.smb.SmbFileInputStream effectively skips bytes instead of transferring them.

If both these checks are true, you may directly pass an SmbFileInputStream to the ZipInputStream constructor and enumerate the zip entries: it shouldn't trigger the transfer of the complete zip file but only of the parts you need...

Il 1 is false, you may eventually google for a more transfer-efficient zip library than the java "stock" one.

If 2 is false, you may develop a class implementing InputStream and wrapping an SmbRandomAccessFile, which should map the skip() and read() methods in the seek() and read() ones, as to limit the transfer of data through smb. Your InputStream implementation may eventually even cache transferred data, in order to further decrease any network access.

Giampaolo



More information about the jcifs mailing list