Example usage for org.apache.commons.io FileUtils writeStringToFile

List of usage examples for org.apache.commons.io FileUtils writeStringToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils writeStringToFile.

Prototype

public static void writeStringToFile(File file, String data) throws IOException 

Source Link

Document

Writes a String to a file creating the file if it does not exist using the default encoding for the VM.

Usage

From source file:com.axiomine.largecollections.generator.GeneratorWritableSet.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];/*from w w w  .j  a v  a  2s . c  o m*/
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "Set";
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/WritableSetTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveSet.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];/* www.j a  v a 2s  .  c  om*/
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "Set";
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveSetTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorWritableList.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];//  w w w . j a v  a  2  s.  c om
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "List";
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/WritableListTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveList.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];//  w w w.j av  a 2s . co  m
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String T = args[2];

    String tCls = T;

    if (tCls.equals("byte[]")) {
        tCls = "BytesArray";
    }
    String CLASS_NAME = tCls + "List";
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveListTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#T#", T);
        program = program.replaceAll("#TCLS#", tCls);

        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.mvdb.etl.actions.FetchConfigValue.java

/**
 * @param args/*from   w w w . j a  v a  2  s.  co  m*/
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    String customerName = null;
    String valueName = null;
    String outputFileName = null;

    ActionUtils.setUpInitFileProperty();

    final CommandLineParser cmdLinePosixParser = new PosixParser();
    final Options posixOptions = constructPosixOptions();
    CommandLine commandLine;
    try {
        commandLine = cmdLinePosixParser.parse(posixOptions, args);
        if (commandLine.hasOption("customer")) {
            customerName = commandLine.getOptionValue("customer");
        }
        if (commandLine.hasOption("name")) {
            valueName = commandLine.getOptionValue("name");
        }
        if (commandLine.hasOption("outputFile")) {
            outputFileName = commandLine.getOptionValue("outputFile");
        }

        System.out.println("customerName:" + customerName);
        System.out.println("valueName:" + valueName);
        System.out.println("outputFileName:" + outputFileName);

    } catch (ParseException parseException) // checked exception
    {
        System.err.println(
                "Encountered exception while parsing using PosixParser:\n" + parseException.getMessage());
    }

    if (customerName == null) {
        System.err.println("Could not find customerName. Aborting...");
        System.exit(1);
    }

    if (valueName == null) {
        System.err.println("Could not find valueName. Aborting...");
        System.exit(1);
    }

    if (outputFileName == null) {
        System.err.println("Could not find outputFileName. Aborting...");
        System.exit(1);
    }

    String value = ActionUtils.getConfigurationValue(customerName, valueName);
    FileUtils.writeStringToFile(new File(outputFileName), value);

}

From source file:com.atlauncher.Bootstrap.java

public static void main(String[] args) {
    String json = null;//from  w  w  w  .  j  a  va2  s  .  c  o  m

    if (!Files.isDirectory(PATH)) {
        try {
            Files.createDirectories(PATH);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    try {
        json = IOUtils.toString(URI.create("http://download.nodecdn.net/containers/atl/v4/app.json"));
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    Application application = GSON.fromJson(json, Application.class);

    Dependency currentDependency = null;

    if (Files.exists(PATH.resolve("nwjs.json"))) {
        try {
            currentDependency = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("nwjs.json").toFile()),
                    Dependency.class);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    for (Dependency dependency : application.getDependencies()) {
        if (dependency.shouldInstall() && !dependency.matches(currentDependency)) {
            if (Files.isDirectory(PATH.resolve("nwjs/"))) {
                try {
                    FileUtils.deleteDirectory(PATH.resolve("nwjs/").toFile());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            try {
                File zipFile = PATH.resolve("nwjs/temp.zip").toFile();
                FileUtils.copyURLToFile(dependency.getUrl(), zipFile);
                Utils.unzip(zipFile, PATH.resolve("nwjs/").toFile());
                FileUtils.forceDelete(zipFile);

                currentDependency = dependency;

                FileUtils.writeStringToFile(PATH.resolve("nwjs.json").toFile(), GSON.toJson(dependency));

                break;
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }

    App currentApp = null;

    if (Files.exists(PATH.resolve("app.json"))) {
        try {
            currentApp = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("app.json").toFile()),
                    App.class);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    if (!application.getApp().matches(currentApp)
            || (currentApp != null && !Files.exists(PATH.resolve(currentApp.getFilename())))) {
        if (currentApp != null && Files.exists(PATH.resolve(currentApp.getFilename()))) {
            try {
                FileUtils.forceDelete(PATH.resolve(currentApp.getFilename()).toFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            FileUtils.copyURLToFile(application.getApp().getUrl(),
                    PATH.resolve(application.getApp().getFilename()).toFile());

            currentApp = application.getApp();

            FileUtils.writeStringToFile(PATH.resolve("app.json").toFile(), GSON.toJson(application.getApp()));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    if (currentDependency == null || currentApp == null) {
        System.exit(1);
    }

    List<String> arguments = new ArrayList<>();
    arguments.add(PATH.resolve("nwjs/").toAbsolutePath() + currentDependency.getStartup());
    arguments.add(currentApp.getFilename());
    ProcessBuilder processBuilder = new ProcessBuilder(arguments);
    processBuilder.directory(PATH.toFile());
    try {
        processBuilder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step1PrepareContainers.java

public static void main(String[] args) throws IOException {
    // queries with narratives in CSV
    File queries = new File(args[0]);
    File relevantInformationExamplesFile = new File(args[1]);

    Map<Integer, Map<Integer, List<String>>> relevantInformationMap = parseRelevantInformationFile(
            relevantInformationExamplesFile);

    // output dir
    File outputDir = new File(args[2]);
    if (!outputDir.exists()) {
        outputDir.mkdirs();/*  ww  w. ja  v  a  2s . c  om*/
    }

    // iterate over queries
    CSVParser csvParser = CSVParser.parse(queries, Charset.forName("utf-8"), CSVFormat.DEFAULT);
    for (CSVRecord record : csvParser) {
        // create new container, fill, and store
        QueryResultContainer container = new QueryResultContainer();
        container.qID = record.get(0);
        container.query = record.get(1);

        // Fill some dummy text first
        container.relevantInformationExamples.addAll(Collections.singletonList("ERROR. Information missing."));
        container.irrelevantInformationExamples
                .addAll(Collections.singletonList("ERROR. Information missing."));

        // and now fill it with existing information if available
        Integer queryID = Integer.valueOf(container.qID);
        if (relevantInformationMap.containsKey(queryID)) {
            if (relevantInformationMap.get(queryID).containsKey(0)) {
                container.irrelevantInformationExamples = new ArrayList<>(
                        relevantInformationMap.get(queryID).get(0));
            }

            if (relevantInformationMap.get(queryID).containsKey(1)) {
                container.relevantInformationExamples = new ArrayList<>(
                        relevantInformationMap.get(queryID).get(1));
            }
        }

        File outputFile = new File(outputDir, container.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, container.toXML());
        System.out.println("Finished " + outputFile);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorKryoKPrimitiveValue.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];//from   www.  ja  va 2  s .  c o  m
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[2];
    //Class name (no packages) of the Key class Ex. String
    //Class name (no packages) of the value class Ex. Integer
    String V = args[3];
    //Specify if you are using a KryoTemplate to generate your classes
    //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used
    //You can customize the name of the class generated
    String vCls = V;

    if (vCls.equals("byte[]")) {
        vCls = "BytesArray";
    }

    String CLASS_NAME = "KryoK" + vCls + "Map"; //Default

    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }
        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/KryoKeyPrimitiveValueMapTemplate.java"));
        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);

        program = program.replaceAll("#VCLS#", vCls);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveKeyKryoValue.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];/*from  www.j  a v a  2 s . c o  m*/
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Class name (no packages) of the Key class Ex. String
    //Class name (no packages) of the value class Ex. Integer
    String K = args[3];
    //Specify if you are using a KryoTemplate to generate your classes
    //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used
    //You can customize the name of the class generated
    String kCls = K;

    if (kCls.equals("byte[]")) {
        kCls = "BytesArray";
    }

    String CLASS_NAME = kCls + "KryoV" + "Map"; //Default

    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }
        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveKeyKryoValueMapTemplate.java"));
        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#K#", K);
        program = program.replaceAll("#KCLS#", kCls);
        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}

From source file:com.axiomine.largecollections.generator.GeneratorPrimitivePrimitive.java

public static void main(String[] args) throws Exception {
    //Package of the new class you are generating Ex. com.mypackage
    String MY_PACKAGE = args[0];/*from   ww w.  j  a  va2s  . c  om*/
    //Any custom imports you need (: seperated). Use - if no custom imports are included
    //Ex. java.util.*:java.lang.Random     
    String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1];
    //Package of your Key serializer class. Use com.axiomine.bigcollections.functions
    String KPACKAGE = args[2];
    //Package of your value serializer class. Use com.axiomine.bigcollections.functions
    String VPACKAGE = args[3];
    //Class name (no packages) of the Key class Ex. String
    String K = args[4];
    //Class name (no packages) of the value class Ex. Integer
    String V = args[5];

    String kCls = K;
    String vCls = V;

    if (kCls.equals("byte[]")) {
        kCls = "BytesArray";
    }
    if (vCls.equals("byte[]")) {
        vCls = "BytesArray";
    }

    String CLASS_NAME = kCls + vCls + "Map"; //Default
    //String templatePath = args[5];
    File root = new File("");
    File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/"
            + CLASS_NAME + ".java");

    if (outFile.exists()) {
        System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again");
    }
    {
        String[] imports = null;
        String importStr = "";

        if (!StringUtils.isBlank(CUSTOM_IMPORTS)) {
            CUSTOM_IMPORTS.split(":");
            for (String s : imports) {
                importStr = "import " + s + ";\n";
            }
        }

        String program = FileUtils.readFileToString(
                new File(root.getAbsolutePath() + "/src/main/resources/JavaLangBasedMapTemplate.java"));

        program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE);
        program = program.replaceAll("#CUSTOM_IMPORTS#", importStr);

        program = program.replaceAll("#CLASS_NAME#", CLASS_NAME);
        program = program.replaceAll("#K#", K);
        program = program.replaceAll("#V#", V);
        program = program.replaceAll("#KCLS#", kCls);
        program = program.replaceAll("#VCLS#", vCls);

        program = program.replaceAll("#KPACKAGE#", KPACKAGE);
        program = program.replaceAll("#VPACKAGE#", VPACKAGE);
        System.out.println(outFile.getAbsolutePath());
        FileUtils.writeStringToFile(outFile, program);
    }
}