Example usage for org.apache.commons.vfs2.util RandomAccessMode getModeString

List of usage examples for org.apache.commons.vfs2.util RandomAccessMode getModeString

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.util RandomAccessMode getModeString.

Prototype

public String getModeString() 

Source Link

Usage

From source file:com.github.songsheng.vfs2.provider.nfs.NfsFileRandomAccessContent.java

public NfsFileRandomAccessContent(final XFile NfsFile, final RandomAccessMode mode) throws FileSystemException {
    super(mode);// www  .j a v  a  2 s  .  c  om

    try {
        raf = new XRandomAccessFile(NfsFile, mode.getModeString());
        rafis = new InputStream() {
            @Override
            public int available() throws IOException {
                final long available = raf.length() - raf.getFilePointer();
                if (available > Integer.MAX_VALUE) {
                    return Integer.MAX_VALUE;
                }

                return (int) available;
            }

            @Override
            public void close() throws IOException {
                raf.close();
            }

            @Override
            public int read() throws IOException {
                return raf.readByte();
            }

            @Override
            public int read(final byte[] b) throws IOException {
                return raf.read(b);
            }

            @Override
            public int read(final byte[] b, final int off, final int len) throws IOException {
                return raf.read(b, off, len);
            }

            @Override
            public long skip(final long n) throws IOException {
                raf.seek(raf.getFilePointer() + n);
                return n;
            }
        };
    } catch (final MalformedURLException e) {
        throw new FileSystemException("vfs.provider/random-access-open-failed.error", NfsFile, e);
    } catch (final UnknownHostException e) {
        throw new FileSystemException("vfs.provider/random-access-open-failed.error", NfsFile, e);
    } catch (IOException e) {
        throw new FileSystemException("vfs.provider/random-access-open-failed.error", NfsFile, e);
    }
}