if(stdinBytes > 0 ) {
if(cmd.hasOption("l")) { printLine("Loading files..."); load loader = new load(); for(Iterator i = cmd.getArgList().iterator(); i.hasNext();) { File file = new File(i.next().toString()); String uri = loader.getUri(cmd.getOptionValue("i"), file.getName()); loader.loadDocument(this, uri, file); } } else if(stdinBytes > 0 ) {
    private void run(String[] args) {        CommandLineParser parser = new PosixParser();        CommandLine cmd = null;        try {            cmd = parser.parse( options, args);        } catch(ParseException e) {            exitWithError(e.getMessage());        }        if(cmd.hasOption("h") ) {            printHelp();        }        String user = cmd.getOptionValue("u");        String password = cmd.getOptionValue("p");        String host = cmd.getOptionValue("H");        Integer port = null;        try {            port = new Integer(cmd.getOptionValue("P"));        } catch(NumberFormatException ignored) { }        if(user == null || password == null || port == null || host == null){            if(user == null) user = properties.getString("user");            if(password == null) password = properties.getString("password");            if(host == null) host = properties.getString("host");            if(port == null) {                try {                        port = new Integer(properties.getInt("port", DEFAULT_PORT));                   } catch(ConversionException e) {                    printHelp("Invalid port number: " + properties.getString("port"));                }            }            if(user == null || password == null || port == null || host == null ){                printHelp("You must provide a user, password, host and port.");            }        }        properties.setProperty("user", user);        properties.setProperty("password", password);        properties.setProperty("host", host);        properties.setProperty("port", port.toString());        if(properties.getString("scroll") == null || properties.getString("scroll").length() <= 0) {            properties.setProperty("scroll", String.valueOf(DEFAULT_SCROLL));        }                if(cmd.hasOption("F") ) {            properties.setProperty("pretty-print-xml", "true");        }                    String xqueryFile = cmd.getOptionValue("f");        InputStream in = null;        if( xqueryFile != null ) {            try {                in = new FileInputStream(new File(xqueryFile));            } catch(FileNotFoundException e) {                exitWithError("File " + xqueryFile + " not found: " + e.getMessage());            }        } else {            in = System.in;        }        int stdinBytes = 0;        try {            stdinBytes = in.available();           } catch(IOException ignored) { }        if(stdinBytes > 0 ) {            StringBuffer xquery = new StringBuffer();            try {                BufferedReader reader = new BufferedReader(new InputStreamReader(in));                char[] b = new char[4*1024];                int n;                while((n = reader.read(b)) > 0 ) {                    xquery.append(b, 0, n);                }                try {                		ShellQuery squery = new ShellQuery(xquery.toString(), this);					runXQuery(squery.asXQuery(), false, false);				} catch(XQException e) {                		printError(e);                }            } catch(IOException e) {                exitWithError("Failed to read query from stdin: " + e.getMessage());            }		} else {			try {				checkConnection(				               properties.getString("user"),				               properties.getString("password"),							  properties.getString("host"),							  properties.getInt("port", DEFAULT_PORT) );			} catch(XQException e) {				printLine("Failed to connect to Mark Logic. Invalid connection information.");				printError(e);				exitWithError("Goodbye.");			}			printWelcome();			printLine("");            try {	            startShell();            } catch(Exception e) {                printLine("Shell exited abnormally with exception: " + e.getClass().toString());                printLine("Error message: " + e.getMessage());                printLine("Goodbye.");            }        }    }