Package org.nimbustools.auto_config

Examples of org.nimbustools.auto_config.TextFile


            System.out.println("    ... already set to " + setString);
            System.out.println("    ... in the file '" + conf.getCanonicalPath() + "'");
            return; // *** EARLY RETURN ***
        }

        final TextFile textFile = new TextFile(conf.getAbsolutePath());
        if (textFile.isEmpty()) {
            throw new Exception("File is empty? '" +
                    conf.getAbsolutePath() + "'");
        }

        boolean replaced = false;
        final int size = textFile.size();
        for (int i = 0; i < size; i++) {
            final String line = (String) textFile.get(i);
            if (line != null && line.trim().length() > 0) {
                if (line.trim().startsWith(keyword)) {
                    final String newline;
                    if (newvalue == null) {
                        newline = "#" + keyword + "=";
                    } else {
                        newline = keyword + "=" + newvalue.trim();
                    }
                    textFile.set(i, newline);
                    replaced = true;
                    break;
                }
            }
        }

        if (!replaced) {
            // race condition with getProperty() on file contents?
            throw new Exception("Could not alter the configuration file, no '" +
                    keyword + "' setting present in the file '" +
                    conf.getAbsolutePath() + "' (?)");
        }

        textFile.writeFile(conf);

        System.out.println("[*] The '" + keyword + "' configuration was:");
        if (newvalue == null) {
            System.out.println("    ... commented out");
        } else if (newvalue.trim().length() == 0) {
View Full Code Here


        if (!file.exists()) {
            throw new Exception(
                    "unexpected, file does not exist: '" + filePath + "'");
        }

        final TextFile textFile = new TextFile(filePath);
        if (textFile.isEmpty()) {
            return;
        }

        if (!file.canWrite()) {
            throw new Exception(
                    "This file is not writable: '" + filePath + "'");
        }

        int count = 0;

        // see note for _removeAttempt
        while (_removeAttempt(textFile, dn)) {
            count++;
        }

        if (count > 0) {
            textFile.writeFile(file);
            if (count == 1) {
                System.out.println("Deleted from group '" + groupName + "'");
            } else {
                System.out.println("Deleted " + count +
                        " instances of the DN from group '" + groupName + "'");
View Full Code Here

        if (!file.exists()) {
            throw new Exception(
                    "unexpected, file does not exist: '" + filePath + "'");
        }

        final TextFile textFile = new TextFile(filePath);

        if (!file.canWrite()) {
            throw new Exception(
                    "This file is not writable: '" + filePath + "'");
        }

        textFile.add(dn);
        textFile.writeFile(file);
    }
View Full Code Here

TOP

Related Classes of org.nimbustools.auto_config.TextFile

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.