Package org.jboss.aesh.io

Examples of org.jboss.aesh.io.Resource


            String fileContent = s.hasNext() ? s.next() : "";
            setInput(fileContent);
            afterAttach();
        }
        else if(arguments != null && arguments.size() > 0) {
            Resource f =
                    arguments.get(0).resolve(commandInvocation.getAeshContext().getCurrentWorkingDirectory()).get(0);
            if(f.isLeaf()) {
                if(color) {
                    String content = readFile(f.read());

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();

                    Syntax.builtIns();
                    Syntax.Builder.create()
                            .encoderType(Encoder.Type.TERMINAL)
                            .output(baos)
                            .scanner(Scanner.Factory.byFileName(f.getName()))
                            .execute(content);

                    setInput(new String(baos.toByteArray()));
                    afterAttach();
                }
                else {
                    setFile(f.read(), f.getName());
                    afterAttach();
                }
            }
            else if(f.isDirectory()) {
                getShell().err().println(f.getAbsolutePath()+": is a directory");
            }
            else {
                getShell().err().println(f.getAbsolutePath() + ": No such file or directory");
            }
        }

        return CommandResult.SUCCESS;
    }
View Full Code Here


    @Override
    public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {

        try {
            Pushd pushd = (Pushd) commandInvocation.getCommandRegistry().getCommand("pushd", "").getCommand();
            Resource popFile = pushd.popDirectory();
            if(popFile != null) {
                commandInvocation.getAeshContext().setCurrentWorkingDirectory(popFile);
                return CommandResult.SUCCESS;
            }
            else {
View Full Code Here

        else if(arguments != null && arguments.size() > 0) {

            List<Resource> files = arguments.get(0).resolve(commandInvocation.getAeshContext().getCurrentWorkingDirectory());

            if(files.get(0).isDirectory()) {
                Resource oldCwd = commandInvocation.getAeshContext().getCurrentWorkingDirectory();
                directories.add(oldCwd);
                commandInvocation.getAeshContext().setCurrentWorkingDirectory(files.get(0));
                commandInvocation.getShell().out().println(files.get(0)+" "+getDirectoriesAsString());
                return CommandResult.SUCCESS;
            }
View Full Code Here

        if (help || arguments == null || arguments.isEmpty()) {
            commandInvocation.getShell().out().println(commandInvocation.getHelpInfo("rm"));
            return CommandResult.SUCCESS;
        }

        Resource currentWorkingDirectory = commandInvocation.getAeshContext().getCurrentWorkingDirectory();
        for (Resource r : arguments) {

            Shell shell = commandInvocation.getShell();
            Resource resource = r.resolve(currentWorkingDirectory).get(0);
            if (dir) {
                rmDir(resource, commandInvocation);
            } else {
                rmFile(resource, commandInvocation);
            }
View Full Code Here

            commandInvocation.getShell().out().print("touch: Invalid arguments");
            return CommandResult.FAILURE;
        }

        try {
            Resource currentWorkingDirectory = commandInvocation.getAeshContext().getCurrentWorkingDirectory();
            for (Resource file : arguments) {
                if (file.exists()) {
                    file.setLastModified(System.currentTimeMillis());
                }
                try (OutputStream out  = file.resolve(currentWorkingDirectory).get(0).write(false)) {
View Full Code Here

    public CommandResult execute(CommandInvocation commandInvocation) throws IOException {
        this.commandInvocation = commandInvocation;

        if(files != null && files.size() > 0) {
            if(files.get(0).isLeaf()) {
                Resource f = files.get(0).resolve(commandInvocation.getAeshContext().getCurrentWorkingDirectory()).get(0);
                loadCommand(f);
            }
        }

        return CommandResult.SUCCESS;
View Full Code Here

            String fileContent = s.hasNext() ? s.next() : "";
            setInput(fileContent);
            afterAttach();
        }
        else if(arguments != null && arguments.size() > 0) {
            Resource f = arguments.get(0);
            f = f.resolve(commandInvocation.getAeshContext().getCurrentWorkingDirectory()).get(0);
            if(f.isLeaf()) {
                setInput(f.read(), f.getName());
                afterAttach();
            }
            else if(f.isDirectory()) {
                commandInvocation.getShell().err().println(f.getAbsolutePath()+": is a directory");
            }
            else {
                commandInvocation.getShell().err().println(f.getAbsolutePath() + ": No such file or directory");
            }
        }

        return CommandResult.SUCCESS;
    }
View Full Code Here

            commandInvocation.getShell().out().println(commandInvocation.getHelpInfo("mkdir"));
            return CommandResult.SUCCESS;
        }

        for (Resource f : arguments) {
            Resource currentWorkingDirectory = commandInvocation.getAeshContext().getCurrentWorkingDirectory();
            Shell shell = commandInvocation.getShell();

            Resource pathResolved = f.resolve(currentWorkingDirectory).get(0);

            if (parents || f.getName().contains(Config.getPathSeparator())) {
                makeDirs(arguments, pathResolved, shell);
            } else {
                makeDir(pathResolved, shell);
View Full Code Here

                ConsoleOperation nextOperation = operations.remove(0);
                if( nextOperation.getBuffer().length() > 0) {
                    AeshLine line = Parser.findAllWords(nextOperation.getBuffer());
                    currentOperation = new ConsoleOperation(nextOperation.getControlOperator(), op.getBuffer());

                    Resource fileRelativePath =
                            getAeshContext().getCurrentWorkingDirectory().newInstance(
                                    Parser.switchEscapedSpacesToSpacesInWord(line.getWords().get(0)));

                    Resource readFile = fileRelativePath.resolve( context.getCurrentWorkingDirectory()).get(0);
                    if(readFile.isLeaf()) {
                        standardStream.setStdIn(new BufferedInputStream( readFile.read()));
                        output = new ConsoleOperation(nextOperation.getControlOperator(),op.getBuffer());
                    }
                    else {
                        err().println(settings.getName() + ": " + readFile.toString()+ " no such file.");
                        currentOperation = null;
                        output = new ConsoleOperation(ControlOperator.NONE, op.getBuffer());
                    }
                }
                else {
View Full Code Here

                ConsoleOperation nextOperation = operations.remove(0);
                if( nextOperation.getBuffer().length() > 0) {
                    AeshLine line = Parser.findAllWords(nextOperation.getBuffer());
                    currentOperation = new ConsoleOperation(nextOperation.getControlOperator(), op.getBuffer());

                    Resource fileRelativePath =
                            getAeshContext().getCurrentWorkingDirectory().newInstance(
                                    Parser.switchEscapedSpacesToSpacesInWord(line.getWords().get(0)));

                    Resource readFile = fileRelativePath.resolve( context.getCurrentWorkingDirectory()).get(0);
                    if(readFile.isLeaf()) {
                        standardStream.setStdIn(new BufferedInputStream( readFile.read()));
                        output = new ConsoleOperation(nextOperation.getControlOperator(),op.getBuffer());
                    }
                    else {
                        err().println(settings.getName() + ": " + readFile.toString()+ " no such file.");
                        currentOperation = null;
                        output = new ConsoleOperation(ControlOperator.NONE, op.getBuffer());
                    }
                }
                else {
View Full Code Here

TOP

Related Classes of org.jboss.aesh.io.Resource

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.