[jcifs] SmbRandomAccessFile for read-only access

Somnath Kundu skundu07 at gmail.com
Thu Jun 6 01:27:41 MDT 2013


Hello,

I was trying to use 'SmbRandomAccessFile' class with mode value "r" for
reading some file data, but it was not working. From the source code, it
appears that for mode value "r", the 'access' value remains set to '0', and
hence this problem. I had to modify the code as below to make it working.

BTW, what is the meaning of 'WRITE_OPTIONS' value as '0x0842' (as I do not
see any description in the code), and I see the default zero value is being
converted to '0x0040' later in the code?

-----------------Original code v1.3.17--------------
    private static final int WRITE_OPTIONS = 0x0842;
    ........
    private int openFlags, access = 0, readSize, writeSize, ch, options = 0;
    ......
    public SmbRandomAccessFile( SmbFile file, String mode )
            throws SmbException, MalformedURLException,
UnknownHostException {
        this.file = file;
        if( mode.equals( "r" )) {
            this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDONLY;
        } else if( mode.equals( "rw" )) {
            this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDWR |
SmbFile.O_APPEND;
            write_andx_resp = new SmbComWriteAndXResponse();
            options = WRITE_OPTIONS;
            access = SmbConstants.FILE_READ_DATA |
SmbConstants.FILE_WRITE_DATA;
        } else {
            throw new IllegalArgumentException( "Invalid mode" );
        }
        .........
    }
-----------------Modified code----------------------------------
    ........
    public SmbRandomAccessFile( SmbFile file, String mode )
            throws SmbException, MalformedURLException,
UnknownHostException {
        this.file = file;
        if( mode.equals( "r" )) {
            this.openFlags = SmbFile.O_RDONLY;
            access = SmbConstants.FILE_READ_DATA;
        } else if( mode.equals( "rw" )) {
            this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDWR |
SmbFile.O_APPEND;
            write_andx_resp = new SmbComWriteAndXResponse();
            options = WRITE_OPTIONS;
            access = SmbConstants.FILE_READ_DATA |
SmbConstants.FILE_WRITE_DATA;
        } else {
            throw new IllegalArgumentException( "Invalid mode" );
        }
-------------------------------------------------------------------

Many thanks for providing this library free of cost.

Beast regards,
Somnath Kundu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/jcifs/attachments/20130606/4c13bfce/attachment-0001.html>


More information about the jCIFS mailing list