Examples of VfsService


Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String fileName = commandLine.getArgs()[0];
        String parentFileID = session.getCurrentDirectory().getID();

        try {
            vfsService.createFile(sessionID, parentFileID, fileName);
        } catch (SessionException e) {
            session.clearSessionID();
            throw new IllegalStateException("ERROR: session time out.");
        } catch (VfsIOException e) {
            System.out.println("ERROR: " + e.getMessage());
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String dirName = commandLine.getArgs()[0];
        VfsFile parent = session.getCurrentDirectory();

        try {
            VfsFile targetFile = null;
            if (dirName.equals("..")) {
                if (parent.getParentID().equals("-1"))
                    return;
                targetFile = vfsService.getVfsFile(
                        sessionID, parent.getParentID());
            } else {
                targetFile = vfsService.getVfsFile(
                        sessionID, parent.getID(), dirName);
            }
            if (targetFile == null) {
                System.out.println(
                        "ERROR: [" + dirName + "] not found.");
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        // parse command line parameters.
        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        // retrives command line parameters.
        boolean isAdmin = commandLine.hasOption("a");
        String[] buf = commandLine.getArgs();
        if (buf.length == 0) {
            printUsage("ERROR: Login name not found.");
            return;
        }

        String loginName = buf[0];
        String password = null;
        while (true) {
            String password1 = ConsoleUtil.readRequiredData("input password");
            if (password1 == null || password1.trim().length() == 0) {
                System.out.println("BAD PASSWORD. ");
                continue;
            }
            String password2 = ConsoleUtil.readRequiredData("input confirm");
            if (!password1.equals(password2)) {
                System.out.println("UNMATCH PASSWORD.");
                continue;
            }
            password = password1;
            break;
        }

        try {
            vfsService.addUser(sessionID, loginName, password, isAdmin);
            System.out.println("User [" + loginName + "] added.");
        } catch (PermissionException e) {
            System.out.println("ERROR: add user failed. (" + e.getMessage() + ")");
        } catch (SessionException e) {
            session.clearSessionID();
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        // get password from console.
        String password = ConsoleUtil.readRequiredData("password");

        try {
            VfsService vfsService = VfsContext.getService();
            session.setSessionID(vfsService.login(loginName, password));
            String sessionID = session.getSessionID();
            VfsFile home = vfsService.getVfsFile(sessionID, "-1", "Home");
            if (home == null)
                throw new IllegalStateException(
                        "User home directory not found.");
            session.setCurrentDirectory(home);
            System.out.println("SessionID = " + session.getSessionID());
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        VfsFile curDir = session.getCurrentDirectory();

        try {
            VfsFile parent = curDir;
            LinkedList<VfsFile> pathList = new LinkedList<VfsFile>();
            while (!parent.getParentID().equals("-1")) {
                pathList.addFirst(parent);
                String parentID = parent.getParentID();
                parent = vfsService.getVfsFile(sessionID, parentID);
                if (parent == null)
                    throw new IllegalStateException(
                            "ERROR: parent directory not found.");
            }
            StringBuffer sb = new StringBuffer();
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String dirName = commandLine.getArgs()[0];
        String parentFileID = session.getCurrentDirectory().getID();

        try {
            VfsFile targetFile =
                vfsService.getVfsFile(sessionID, parentFileID, dirName);
            if (targetFile == null) {
                System.out.println("ERROR: [" + dirName + "] not found.");
                return;
            }
            if (targetFile.getType() != VfsFile.FileType.DIRECTORY) {
                System.out.println(
                        "ERROR: [" + dirName + "] is not directory.");
                return;
            }
            vfsService.deleteObject(sessionID, targetFile.getID());
        } catch (VfsIOException e) {
            System.out.println("ERROR: " + e.getMessage());
        } catch (SessionException e) {
            session.clearSessionID();
            System.out.println("ERROR: Session time out.");
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine cl = null;
        try {
            cl = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        if (cl.getArgs() == null || cl.getArgs().length != 2) {
            printUsage("ERROR: require local_file_path and vfs_file_name");
            return;
        }

        // get local file path.
        File file = new File(cl.getArgs()[0]);
        if (!file.exists()) {
            System.out.println("ERROR: the file not found.");
            return;
        }

        if (!file.isFile()) {
            System.out.println("ERROR: the file not file.");
            return;
        }

        if (!file.canRead()) {
            System.out.println("ERROR: the file access denied.");
            return;
        }

        SystemInfo systemInfo = vfsService.getSystemInfo();
        String parentFileID = session.getCurrentDirectory().getID();
        String fileSessionID = null;
        try {
            VfsFile vfsFile = vfsService.createFile(
                    sessionID, parentFileID, cl.getArgs()[1]);

            if (vfsService.isExistsName(
                        sessionID, vfsFile.getID(), cl.getArgs()[1]))
            {
                System.out.println("ERROR: the vfs_file_name already used.");
                return;
            }

            fileSessionID = vfsService.createFileSession(
                    sessionID, vfsFile.getID(), FileSession.Mode.WRITE);

            byte[] buf = new byte[systemInfo.getBytesPerWrite()];
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(file);
                int count = 0;
                while ((count = fis.read(buf)) != -1)
                    vfsService.writeData(sessionID, fileSessionID, buf, count);
            } catch (IOException e) {
                e.printStackTrace(System.err);
            } finally {
                if (fis != null)
                    try {
                        fis.close();
                    } catch (IOException e) {
                    }
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        } finally {
            if (fileSessionID != null)
                try {
                    vfsService.closeFileSession(sessionID, fileSessionID);
                } catch (Exception e) {
                    e.printStackTrace(System.err);
                }
        }
    }
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String dirName = commandLine.getArgs()[0];
        String parentFileID = session.getCurrentDirectory().getID();

        try {
            vfsService.createDirectory(sessionID, parentFileID, dirName);
        } catch (VfsIOException e) {
            System.out.println("ERROR: " + e.getMessage());
        } catch (SessionException e) {
            session.clearSessionID();
            System.out.println("ERROR: Session time out.");
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine cl = null;
        try {
            cl = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        if (cl.getArgs() == null || cl.getArgs().length != 2) {
            printUsage("ERROR: require local_file_path and vfs_file_name");
            return;
        }

        // check file path.
        File file = new File(cl.getArgs()[1]);
        if (file.exists()) {
            System.out.println("ERROR: the local file already exists.");
            return;
        }

        SystemInfo systemInfo = vfsService.getSystemInfo();
        String parentFileID = session.getCurrentDirectory().getID();
        String fileSessionID = null;
        try {

            VfsFile vfsFile = vfsService.getVfsFile(
                    sessionID, parentFileID, cl.getArgs()[0]);
            if (vfsFile == null) {
                System.out.println("ERROR: the VfsFile not found.");
                return;
            }
            fileSessionID = vfsService.createFileSession(
                sessionID, vfsFile.getID(), FileSession.Mode.READ);

            byte[] buf = new byte[systemInfo.getBytesPerRead()];
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(file);
                int count = 0;
                while ((count = vfsService.readData(sessionID, fileSessionID, buf, buf.length)) != -1)
                {
                    fos.write(buf, 0, count);
                }
            } catch (IOException e) {
                e.printStackTrace(System.err);
            } finally {
                if (fos != null)
                    try {
                        fos.close();
                    } catch (IOException e) {
                    }
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        } finally {
            if (fileSessionID != null)
                try {
                    vfsService.closeFileSession(sessionID, fileSessionID);
                } catch (Exception e) {
                    e.printStackTrace(System.err);
                }
        }
    }
View Full Code Here

Examples of org.sd_network.vfs.VfsService

        String sessionID = session.getSessionID();
        if (sessionID == null)
            System.out.println("You have already logged out.");

        // logout.
        VfsService vfsService = VfsContext.getService();
        try {
            vfsService.logout(sessionID);
        } catch (VfsIOException e) {
            System.out.println("ERROR: some file session close failed.");
        }
        session.clearSessionID();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.