Package org.jnode.net.nfs.nfs2

Examples of org.jnode.net.nfs.nfs2.Time


     * @param fileOffset
     * @param dest
     * @throws java.io.IOException
     */
    public void read(long fileOffset, ByteBuffer dest) throws IOException {
        NFS2Client client = getNFS2Client();
        try {
            int length;
            while (true) {
                length = Math.min(NFS2Client.MAX_DATA, dest.remaining());
                if (length == 0) {
                    return;
                }
                ReadFileResult result =
                        client.readFile(entry.getFileHandle(), (int) fileOffset, length);
                byte[] data = result.getData();
                length = data.length;
                fileOffset += length;
                dest.put(data);
            }
View Full Code Here


     *
     * @param length
     * @throws java.io.IOException
     */
    public void setLength(long length) throws IOException {
        NFS2Client client = getNFS2Client();
        try {
            client.setAttribute(entry.getFileHandle(), -1, -1, -1, (int) length, new Time(-1, -1),
                    new Time(-1, -1));
        } catch (NFS2Exception e) {
            throw new IOException(e.getMessage(), e);
        }
    }
View Full Code Here

     * @param fileOffset
     * @param src
     * @throws java.io.IOException
     */
    public void write(long fileOffset, ByteBuffer src) throws IOException {
        NFS2Client client = getNFS2Client();
        try {
            byte[] data = new byte[NFS2Client.MAX_DATA];
            int count;
            while (src.remaining() > 0) {
                count = Math.min(NFS2Client.MAX_DATA, src.remaining());
                src.get(data, 0, count);
                client.writeFile(entry.getFileHandle(), (int) fileOffset, data, 0, count);
                fileOffset += count;
            }
        } catch (NFS2Exception e) {
            throw new IOException("Error writing file . Reason: " + e.getMessage(), e);
        }
View Full Code Here

        NFS2Entry entry = tableEntry.getEntry(name);
        if (entry != null) {
            return entry;
        }

        NFS2Client nfsClient = getNFS2Client();
        LookupResult lookupResult;
        try {
            lookupResult = nfsClient.lookup(directoryEntry.getFileHandle(), name);
        } catch (NFS2Exception e) {
            throw new IOException("Can not call the rpc method." + e.getMessage(), e);
        }
        entry = new NFS2Entry(
            (NFS2FileSystem) getFileSystem(), this, name,
View Full Code Here

    /**
     * Gets an iterator used to iterate over all the entries of this directory.
     * All elements returned by the iterator must be instanceof FSEntry.
     */
    public Iterator<? extends NFS2Entry> iterator() throws IOException {
        final NFS2Client nfsClient = getNFS2Client();

        @SuppressWarnings("unused")
        FileAttribute fileAttribute;
        try {
            fileAttribute =
                AccessController.doPrivileged(new PrivilegedExceptionAction<FileAttribute>() {
                    public FileAttribute run() throws Exception {
                        return nfsClient.getAttribute(getNFS2Entry().getFileHandle());
                    }
                });

        } catch (PrivilegedActionException e) {
            Exception x = e.getException();
View Full Code Here

        }
        return nfsEntrySet.iterator();
    }

    private Set<NFS2Entry> getNFS2EntrySet() throws IOException {
        final NFS2Client nfsClient = getNFS2Client();
        Set<NFS2Entry> nfsEntrySet;

        try {
            nfsEntrySet =
                AccessController.doPrivileged(new PrivilegedExceptionAction<Set<NFS2Entry>>() {
                    public Set<NFS2Entry> run() throws Exception {
                        Set<Entry> entrySet = new LinkedHashSet<Entry>();
                        boolean eof = false;
                        byte[] cookie = new byte[NFS2Client.COOKIE_SIZE];
                        while (!eof) {
                            ListDirectoryResult result = nfsClient.listDirectory(
                                directoryEntry.getFileHandle(), cookie, 2048);
                            entrySet.addAll(result.getEntryList());
                            if (result.isEof()) {
                                eof = true;
                            } else {
                                // I guess that the list contains at least one entry.
                                cookie = result.getEntryList().get(
                                    result.getEntryList().size() - 1).getCookie();
                            }
                        }

                        if (entrySet.size() == 0) {
                            return new HashSet<NFS2Entry>();
                        }

                        Set<NFS2Entry> nfsEntrySet =
                            new LinkedHashSet<NFS2Entry>(entrySet.size());

                        for (Entry entry : entrySet) {
                            LookupResult lookupResult = nfsClient.lookup(
                                directoryEntry.getFileHandle(), entry.getName());

                            NFS2Entry nfsEntry = new NFS2Entry(
                                (NFS2FileSystem) getFileSystem(),
                                NFS2Directory.this, entry.getName(), lookupResult.getFileHandle(),
View Full Code Here

    }

    public FSEntry addDirectory(String name) throws IOException {

        NFS2Client nfsClient = getNFS2Client();

        CreateDirectoryResult result;
        try {
            result = nfsClient.createDirectory(directoryEntry.getFileHandle(), name,
                DEFAULT_PERMISSION, -1, -1, -1, new Time(-1, -1), new Time(-1, -1));
        } catch (NFS2Exception e) {
            throw new IOException("Can not create the directory " + name + "." + e.getMessage(), e);
        }
View Full Code Here

        tableEntry.addEntry(entry);
        return entry;
    }

    public FSEntry addFile(String name) throws IOException {
        NFS2Client nfsClient = getNFS2Client();

        CreateFileResult result;
        try {
            result = nfsClient.createFile(directoryEntry.getFileHandle(), name, DEFAULT_PERMISSION,
                -1, -1, -1, new Time(-1, -1), new Time(-1, -1));
        } catch (NFS2Exception e) {
            throw new IOException("Can not create the file " + name + "." + e.getMessage(), e);
        }
View Full Code Here

        NFS2Entry entry = getEntry(name);
        if (entry == null) {
            return;
        }

        NFS2Client nfsClient = getNFS2Client();

        if (entry.isDirectory()) {
            try {
                nfsClient.removeDirectory(directoryEntry.getFileHandle(), name);
            } catch (NFS2Exception e) {
                throw new IOException("Can not remove directory " + name + "." + e.getMessage(), e);
            }
        } else {
            try {
                nfsClient.removeFile(directoryEntry.getFileHandle(), name);
            } catch (NFS2Exception e) {
                throw new IOException("Can not remove file " + name + "." + e.getMessage(), e);
            }
        }
        tableEntry.removeEntry(name);
View Full Code Here

                }
            }
        });

        mountClient = new Mount1Client(device.getHost(), device.getProtocol(), device.getUid(), device.getGid());
        nfsClient = new NFS2Client(device.getHost(), device.getProtocol(), device.getUid(), device.getGid());

        // Mount the file system
        MountResult result;
        FileAttribute fileAttribute;
        try {
View Full Code Here

TOP

Related Classes of org.jnode.net.nfs.nfs2.Time

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.