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:edu.nju.cs.inform.jgit.porcelain.CreateListApplyAndDropStash.java

public static void main(String[] args) throws IOException, GitAPIException {
    // prepare a new test-repository
    try (Repository repository = CookbookHelper.createNewRepository()) {
        try (Git git = new Git(repository)) {
            // create a file
            File file1 = new File(repository.getDirectory().getParent(), "testfile");
            FileUtils.writeStringToFile(file1, "some text");
            File file2 = new File(repository.getDirectory().getParent(), "testfile2");
            FileUtils.writeStringToFile(file2, "some text");

            // add and commit the file
            git.add().addFilepattern("testfile").call();
            git.add().addFilepattern("testfile2").call();
            git.commit().setMessage("Added testfiles").call();

            // then modify the file
            FileUtils.writeStringToFile(file1, "some more text", true);

            // push the changes to a new stash
            RevCommit stash = git.stashCreate().call();

            System.out.println("Created stash " + stash);

            // then modify the 2nd file
            FileUtils.writeStringToFile(file2, "some more text", true);

            // push the changes to a new stash
            stash = git.stashCreate().call();

            System.out.println("Created stash " + stash);

            // list the stashes
            Collection<RevCommit> stashes = git.stashList().call();
            for (RevCommit rev : stashes) {
                System.out.println("Found stash: " + rev + ": " + rev.getFullMessage());
            }// w  ww  .j  ava  2s . co  m

            // drop the 1st stash without applying it
            ObjectId call = git.stashDrop().setStashRef(0).call();
            System.out.println("StashDrop returned: " + call);

            ObjectId applied = git.stashApply().setStashRef(stash.getName()).call();
            System.out.println("Applied 2nd stash as: " + applied);
        }
    }
}

From source file:net.itransformers.bgpPeeringMap.ThirdTransformation.java

public static void main(String[] args) throws Exception {

    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();

    XsltTransformer transformer = new XsltTransformer();
    File xsltFileName1 = new File("/Users/niau/trunk/bgpPeeringMap/conf/xslt/reorder.xslt");

    byte[] rawData = readRawDataFile(
            "/Users/niau/trunk/bgpPeeringMap/src/main/resources/bgpPeeringMap.graphml");
    ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData);
    transformer.transformXML(inputStream1, xsltFileName1, outputStream1);
    File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources",
            "bgpPeeringMap2.graphxml");

    FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray()));

}

From source file:com.xinge.sample.samples.pptx4j.org.pptx4j.samples.ConvertOutFlatOpenPackage.java

/**
 * @param args/*  w ww .  j a  v  a2 s.c  o  m*/
 */
public static void main(String[] args) throws Exception {

    String inputfilepath = System.getProperty("user.dir") + "/sample.pptx";
    OpcPackage pptxPackage = OpcPackage.load(new File(inputfilepath));

    FlatOpcXmlCreator worker = new FlatOpcXmlCreator(pptxPackage);

    org.docx4j.xmlPackage.Package result = worker.get();

    boolean suppressDeclaration = true;
    boolean prettyprint = true;

    String data = org.docx4j.XmlUtils.marshaltoString(result, suppressDeclaration, prettyprint,
            org.docx4j.jaxb.Context.jcXmlPackage);

    FileUtils.writeStringToFile(new File(System.getProperty("user.dir") + "/pptx.xml"), data);

}

From source file:net.itransformers.bgpPeeringMap.DavidPiegzaFormatTransformer.java

public static void main(String[] args) throws Exception {
    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();

    XsltTransformer transformer = new XsltTransformer();
    File xsltFileName1 = new File("/Users/niau/trunk/bgpPeeringMap/conf/xslt/david_piegza.xslt");
    byte[] rawData = readRawDataFile("/Users/niau/test1/network/version1/undirected/imap.graphml");
    ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData);
    transformer.transformXML(inputStream1, xsltFileName1, outputStream1, null, null);
    File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources", "imap.xml");
    FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray()));

}

From source file:gov.nih.nci.caaersinstaller.util.CsmJaasFileCopier.java

public static void main(String args[]) throws Exception {

    //      File csmJaasTemplateFile = new File("/Users/Moni/temp/installer/postgres.csm_jaas.config");
    //      File csmJassConfigFile = new File("/Users/Moni/temp/installer/csm_jaas.config");

    File csmJaasTemplateFile = new File(args[0]);
    File csmJassConfigFile = new File(args[1]);

    if (csmJassConfigFile.exists()) {
        //append content of csmJaasTemplateFile to existing csmJaasConfigFile
        String csmJaasTemplateFileContent = FileUtils.readFileToString(csmJaasTemplateFile);
        StringBuilder stringBuilder = new StringBuilder(FileUtils.readFileToString(csmJassConfigFile));

        int start = stringBuilder.indexOf("caaers {");
        if (start != -1) {
            //If caaers context exisits then replace it.
            int end = stringBuilder.indexOf("};", start);
            end = end + 2;//from ww w.j a  v  a  2 s. c  o m
            stringBuilder.replace(start, end, csmJaasTemplateFileContent);
        } else {
            //if caaers context does not exist then add it 
            stringBuilder.append("\n");
            stringBuilder.append("\n");
            stringBuilder.append(csmJaasTemplateFileContent);
        }

        FileUtils.writeStringToFile(csmJassConfigFile, stringBuilder.toString());
        System.out.println("Modified csm_jaas.config to add caaers context");

    } else {
        //Create a new File with Contents of csmJaasTemplateFile
        FileUtils.copyFile(csmJaasTemplateFile, csmJassConfigFile);
        System.out.println("Created csm_jaas.config");

    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.flextag.model.InstallAsMavenArtifact.java

public static void main(String[] args) throws IOException {

    String modelLocation = "PathToTheFolderContainingTheModelFiles";

    String version = "VersionId"; //i.e. a data YYYYMMDD
    String language = "en";
    String variant = "YourModelNameHere";

    String modelencoding = "encoding"; // i.e. utf-8
    String postagset = "tagset"; //en=ptb, de=stts, etc

    String targetName = language + "-" + variant;
    String workingDirectory = Files.createTempDirectory("installModel", new FileAttribute<?>[] {})
            .toAbsolutePath().toString();

    String preparedScript = prepareBuildScript(modelLocation, groupId, artifactId, version, tool, language,
            variant, targetName, workingDirectory, modelencoding, postagset);

    File script = new File(workingDirectory + "/build.xml");
    FileUtils.writeStringToFile(script, preparedScript);

    runAntToInstall(script);/*from  w  ww . j  ava  2  s.c o  m*/

}

From source file:com.moscona.dataSpace.debug.BadLocks.java

public static void main(String[] args) {
    try {//from w  w w.jav a 2s .  c  o  m
        String lockFile = "C:\\Users\\Admin\\projects\\intellitrade\\tmp\\bad.lock";
        FileUtils.touch(new File(lockFile));
        FileOutputStream stream = new FileOutputStream(lockFile);
        //            FileInputStream stream = new FileInputStream(lockFile);
        FileChannel channel = stream.getChannel();
        //            FileLock lock = channel.lock(0,Long.MAX_VALUE, true);
        FileLock lock = channel.lock();
        stream.write(new UndocumentedJava().pid().getBytes());
        stream.flush();
        long start = System.currentTimeMillis();
        //            while (System.currentTimeMillis()-start < 10000) {
        //                Thread.sleep(500);
        //            }
        lock.release();
        stream.close();
        File f = new File(lockFile);
        System.out.println("Before write: " + FileUtils.readFileToString(f));
        FileUtils.writeStringToFile(f, "written after lock released");
        System.out.println("After write: " + FileUtils.readFileToString(f));
    } catch (Exception e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

}

From source file:dpfmanager.shell.core.util.VersionUtil.java

public static void main(String[] args) {
    String version = args[0];/*from  ww w  .ja  v  a 2 s  .  co m*/
    String baseDir = args[1];

    String issPath = baseDir + "/package/windows/DPF Manager.iss";
    String rpmPath = baseDir + "/package/linux/DPFManager.old.spec";
    String propOutput = baseDir + "/target/classes/version.properties";

    try {
        // Windows iss
        File issFile = new File(issPath);
        String issContent = FileUtils.readFileToString(issFile);
        String newIssContent = replaceLine(StringUtils.split(issContent, '\n'), "AppVersion=", version);
        if (!newIssContent.isEmpty()) {
            FileUtils.writeStringToFile(issFile, newIssContent);
            System.out.println("New version information updated! (iss)");
        }

        // RPM spec
        File rpmFile = new File(rpmPath);
        String rpmContent = FileUtils.readFileToString(rpmFile);
        String newRpmContent = replaceLine(StringUtils.split(rpmContent, '\n'), "Version: ", version);
        if (!newRpmContent.isEmpty()) {
            FileUtils.writeStringToFile(rpmFile, newRpmContent);
            System.out.println("New version information updated! (spec)");
        }

        // Java properties file
        OutputStream output = new FileOutputStream(propOutput);
        Properties prop = new Properties();
        prop.setProperty("version", version);
        prop.store(output, "Version autoupdated");
        output.close();
        System.out.println("New version information updated! (properties)");

    } catch (Exception e) {
        System.out.println("Exception ocurred, no version changed.");
        e.printStackTrace();
    }

}

From source file:de.tudarmstadt.ukp.dkpro.core.flextag.InstallAsMavenArtifact.java

public static void main(String[] args) throws IOException {

    String modelLocation = "/Users/toobee/Desktop/shrdTaskModel";

    String version = "20160330"; //i.e. a data YYYYMMDD
    String language = "de";
    String variant = "empiri";

    String modelencoding = "utf-8"; // i.e. utf-8
    String postagset = "stts"; //en=ptb, de=stts, etc

    String targetName = language + "-" + variant;
    String workingDirectory = Files.createTempDirectory("installModel", new FileAttribute<?>[] {})
            .toAbsolutePath().toString();

    String preparedScript = prepareBuildScript(modelLocation, groupId, artifactId, version, tool, language,
            variant, targetName, workingDirectory, modelencoding, postagset);

    File script = new File(workingDirectory + "/build.xml");
    FileUtils.writeStringToFile(script, preparedScript);

    runAntToInstall(script);//from  w w w.  ja v  a2s .  co m

}

From source file:com.e2info.helloasm.HelloAsmApp.java

public static void main(String[] args) throws IOException {
    String name = "HelloAsm";
    int flag = ClassWriter.COMPUTE_MAXS;
    ClassWriter cw = new ClassWriter(flag);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null);

    cw.visitSource(name + ".java", null);

    {/*w w w . j a v  a2s. c o m*/
        MethodVisitor mv;
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
        mv.visitInsn(Opcodes.RETURN);
        // we need this call to take effect ClassWriter.COMPUTE_MAXS flag.
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    {
        MethodVisitor mv;
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null,
                null);
        mv.visitCode();
        mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("hello ASM");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
        mv.visitInsn(Opcodes.RETURN);
        // we need this call to take effect ClassWriter.COMPUTE_MAXS flag.
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }

    cw.visitEnd();

    // build binary
    byte[] bin = cw.toByteArray();

    // save asm trace for human readable
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        new ClassReader(bin).accept(new TraceClassVisitor(pw), 0);
        File f = new File(name + ".txt");
        FileUtils.writeStringToFile(f, sw.toString());
    }

    // save as calss file
    {
        File f = new File(name + ".class");
        FileUtils.writeByteArrayToFile(f, bin);
    }

}