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:ch.sbb.releasetrain.git.GITAccessor.java

public void reset() {

    writeModel();/*from   ww  w. j a va2s . c om*/

    repo = client.gitRepo(model.getConfigUrl(), model.getConfigBranch(), model.getConfigUser(),
            model.getEncPassword());

    err = "";
    read = false;
    write = false;
    repo.reset();

    try {
        repo.cloneOrPull();
        read = true;
        File dir = repo.directory();
        FileUtils.writeStringToFile(new File(dir, "test.txt"), new Date().toString());
        repo.addCommitPush();
        write = true;
        FileUtils.forceDelete(new File(dir, "test.txt"));
        repo.addCommitPush();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        err = e.getMessage();
    }
}

From source file:edu.pitt.dbmi.facebase.hd.domain.InstructionsText.java

/** Makes the actual text file (ie. FBuserAgreement.txt).  
 * Uses apache commons FileUtils.writeStringToFile() to turn the String into a file. 
 *
 * @throws IOException/*from   w  w  w  .  j  ava 2  s  . c  o m*/
 * @return size of the file.
 */
public long makeFiles() throws IOException {
    log.debug("InstructionsText.makeFiles() called, about to write to file:");
    log.debug(destinationFile);
    FileUtils.writeStringToFile(destinationFile, fileContents);
    return destinationFile.length();
}

From source file:com.mtgi.io.RelocatableFileTest.java

@Test
public void testRelocate() throws IOException, ClassNotFoundException {
    FileUtils.writeStringToFile(source, "here is some data");

    output.writeObject(inst);//from w  ww.  j a  v a2s . co m
    output.close();

    assertTrue("original file still here", inst.getLocalFile().isFile());
    assertEquals("source file is unchanged", "here is some data",
            FileUtils.readFileToString(inst.getLocalFile()));

    RelocatableFile transferred = (RelocatableFile) new ObjectInputStream(
            new ByteArrayInputStream(buffer.toByteArray())).readObject();
    assertNotNull("file loaded", transferred);
    assertNotNull("local file defined", transferred.getLocalFile());
    assertTrue("local file exists", transferred.getLocalFile().isFile());
    assertFalse("reloaded file points to a new path",
            inst.getLocalFile().getCanonicalPath().equals(transferred.getLocalFile().getCanonicalPath()));

    assertEquals("transferred file contains source data", "here is some data",
            FileUtils.readFileToString(transferred.getLocalFile()));
    assertTrue("transferred file is closed", transferred.getLocalFile().delete());
}

From source file:Pathway2RDFv2.java

public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException,
        ServiceException, ClassNotFoundException, IDMapperException, ParseException {

    int softwareVersion = 0;
    int schemaVersion = 0;
    int latestRevision = 0;

    BioDataSource.init();//w  w w.  j  a va 2 s .  c o m
    Class.forName("org.bridgedb.rdb.IDMapperRdb");
    File dir = new File("/Users/andra/Downloads/bridge");
    File[] bridgeDbFiles = dir.listFiles();
    IDMapperStack mapper = new IDMapperStack();
    for (File bridgeDbFile : bridgeDbFiles) {
        System.out.println(bridgeDbFile.getAbsolutePath());
        mapper.addIDMapper("idmapper-pgdb:" + bridgeDbFile.getAbsolutePath());
    }

    Model bridgeDbmodel = ModelFactory.createDefaultModel();
    InputStream in = new FileInputStream("/tmp/BioDataSource.ttl");
    bridgeDbmodel.read(in, "", "TURTLE");

    WikiPathwaysClient client = new WikiPathwaysClient(
            new URL("http://www.wikipathways.org/wpi/webservice/webservice.php"));

    basicCalls.printMemoryStatus();

    //Map wikipathway organisms to NCBI organisms
    HashMap<String, String> organismTaxonomy = wpRelatedCalls.getOrganismsTaxonomyMapping();
    //HashMap<String, String> miriamSources = new HashMap<String, String>();
    //      HashMap<String, Str ing> miriamLinks = basicCalls.getMiriamUriBridgeDb();

    //Document wikiPathwaysDom = basicCalls.openXmlFile(args[0]);
    Document wikiPathwaysDom = basicCalls.openXmlFile("/tmp/WpGPML.xml");

    //initiate the Jena model to be populated
    Model model = ModelFactory.createDefaultModel();
    Model voidModel = ModelFactory.createDefaultModel();

    voidModel.setNsPrefix("xsd", XSD.getURI());
    voidModel.setNsPrefix("void", Void.getURI());
    voidModel.setNsPrefix("wprdf", "http://rdf.wikipathways.org/");
    voidModel.setNsPrefix("pav", Pav.getURI());
    voidModel.setNsPrefix("prov", Prov.getURI());
    voidModel.setNsPrefix("dcterms", DCTerms.getURI());
    voidModel.setNsPrefix("biopax", Biopax_level3.getURI());
    voidModel.setNsPrefix("gpml", Gpml.getURI());
    voidModel.setNsPrefix("wp", Wp.getURI());
    voidModel.setNsPrefix("foaf", FOAF.getURI());
    voidModel.setNsPrefix("hmdb", "http://identifiers.org/hmdb/");
    voidModel.setNsPrefix("freq", Freq.getURI());
    voidModel.setNsPrefix("dc", DC.getURI());
    setModelPrefix(model);

    //Populate void.ttl
    Calendar now = Calendar.getInstance();
    Literal nowLiteral = voidModel.createTypedLiteral(now);
    Literal titleLiteral = voidModel.createLiteral("WikiPathways-RDF VoID Description", "en");
    Literal descriptionLiteral = voidModel
            .createLiteral("This is the VoID description for a WikiPathwyas-RDF dataset.", "en");
    Resource voidBase = voidModel.createResource("http://rdf.wikipathways.org/");
    Resource identifiersOrg = voidModel.createResource("http://identifiers.org");
    Resource wpHomeBase = voidModel.createResource("http://www.wikipathways.org/");
    Resource authorResource = voidModel
            .createResource("http://semantics.bigcat.unimaas.nl/figshare/search_author.php?author=waagmeester");
    Resource apiResource = voidModel
            .createResource("http://www.wikipathways.org/wpi/webservice/webservice.php");
    Resource mainDatadump = voidModel.createResource("http://rdf.wikipathways.org/wpContent.ttl.gz");
    Resource license = voidModel.createResource("http://creativecommons.org/licenses/by/3.0/");
    Resource instituteResource = voidModel.createResource("http://dbpedia.org/page/Maastricht_University");
    voidBase.addProperty(RDF.type, Void.Dataset);
    voidBase.addProperty(DCTerms.title, titleLiteral);
    voidBase.addProperty(DCTerms.description, descriptionLiteral);
    voidBase.addProperty(FOAF.homepage, wpHomeBase);
    voidBase.addProperty(DCTerms.license, license);
    voidBase.addProperty(Void.uriSpace, voidBase);
    voidBase.addProperty(Void.uriSpace, identifiersOrg);
    voidBase.addProperty(Pav.importedBy, authorResource);
    voidBase.addProperty(Pav.importedFrom, apiResource);
    voidBase.addProperty(Pav.importedOn, nowLiteral);
    voidBase.addProperty(Void.dataDump, mainDatadump);
    voidBase.addProperty(Voag.frequencyOfChange, Freq.Irregular);
    voidBase.addProperty(Pav.createdBy, authorResource);
    voidBase.addProperty(Pav.createdAt, instituteResource);
    voidBase.addLiteral(Pav.createdOn, nowLiteral);
    voidBase.addProperty(DCTerms.subject, Biopax_level3.Pathway);
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/ncbigene/2678"));
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/pubmed/15215856"));
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/hmdb/HMDB02005"));
    voidBase.addProperty(Void.exampleResource, voidModel.createResource("http://rdf.wikipathways.org/WP15"));
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/obo.chebi/17242"));

    for (String organism : organismTaxonomy.values()) {
        voidBase.addProperty(DCTerms.subject,
                voidModel.createResource("http://dbpedia.org/page/" + organism.replace(" ", "_")));
    }
    voidBase.addProperty(Void.vocabulary, Biopax_level3.NAMESPACE);
    voidBase.addProperty(Void.vocabulary, voidModel.createResource(Wp.getURI()));
    voidBase.addProperty(Void.vocabulary, voidModel.createResource(Gpml.getURI()));
    voidBase.addProperty(Void.vocabulary, FOAF.NAMESPACE);
    voidBase.addProperty(Void.vocabulary, Pav.NAMESPACE);
    //Custom Properties
    String baseUri = "http://rdf.wikipathways.org/";
    NodeList pathwayElements = wikiPathwaysDom.getElementsByTagName("Pathway");

    //BioDataSource.init();
    for (int i = 0; i < pathwayElements.getLength(); i++) {
        Model pathwayModel = createPathwayModel();
        String wpId = pathwayElements.item(i).getAttributes().getNamedItem("identifier").getTextContent();
        String revision = pathwayElements.item(i).getAttributes().getNamedItem("revision").getTextContent();
        String pathwayOrganism = "";
        if (pathwayElements.item(i).getAttributes().getNamedItem("Organism") != null)
            pathwayOrganism = pathwayElements.item(i).getAttributes().getNamedItem("Organism").getTextContent()
                    .trim();
        if (Integer.valueOf(revision) > latestRevision) {
            latestRevision = Integer.valueOf(revision);
        }
        File f = new File("/tmp/" + args[0] + "/" + wpId + "_r" + revision + ".ttl");
        System.out.println(f.getName());
        if (!f.exists()) {

            Resource voidPwResource = wpRelatedCalls.addVoidTriples(voidModel, voidBase,
                    pathwayElements.item(i), client);
            Resource pwResource = wpRelatedCalls.addPathwayLevelTriple(pathwayModel, pathwayElements.item(i),
                    organismTaxonomy);

            // Get the comments
            NodeList commentElements = ((Element) pathwayElements.item(i)).getElementsByTagName("Comment");
            wpRelatedCalls.addCommentTriples(pathwayModel, pwResource, commentElements, wpId, revision);
            // Get the Groups
            NodeList groupElements = ((Element) pathwayElements.item(i)).getElementsByTagName("Group");
            for (int n = 0; n < groupElements.getLength(); n++) {
                wpRelatedCalls.addGroupTriples(pathwayModel, pwResource, groupElements.item(n), wpId, revision);
            }
            // Get all the Datanodes
            NodeList dataNodesElement = ((Element) pathwayElements.item(i)).getElementsByTagName("DataNode");
            for (int j = 0; j < dataNodesElement.getLength(); j++) {
                wpRelatedCalls.addDataNodeTriples(pathwayModel, pwResource, dataNodesElement.item(j), wpId,
                        revision, bridgeDbmodel, mapper);
            }
            // Get all the lines
            NodeList linesElement = ((Element) pathwayElements.item(i)).getElementsByTagName("Line");
            for (int k = 0; k < linesElement.getLength(); k++) {
                wpRelatedCalls.addLineTriples(pathwayModel, pwResource, linesElement.item(k), wpId, revision);
            }
            //Get all the labels
            NodeList labelsElement = ((Element) pathwayElements.item(i)).getElementsByTagName("Label");
            for (int l = 0; l < labelsElement.getLength(); l++) {
                wpRelatedCalls.addLabelTriples(pathwayModel, pwResource, labelsElement.item(l), wpId, revision);
            }
            NodeList referenceElements = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:PublicationXref");
            for (int m = 0; m < referenceElements.getLength(); m++) {
                wpRelatedCalls.addReferenceTriples(pathwayModel, pwResource, referenceElements.item(m), wpId,
                        revision);
            }
            NodeList referenceElements2 = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:publicationXref");
            for (int m = 0; m < referenceElements2.getLength(); m++) {
                wpRelatedCalls.addReferenceTriples(pathwayModel, pwResource, referenceElements2.item(m), wpId,
                        revision);
            }
            NodeList referenceElements3 = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:PublicationXRef");
            for (int m = 0; m < referenceElements3.getLength(); m++) {
                wpRelatedCalls.addReferenceTriples(pathwayModel, pwResource, referenceElements3.item(m), wpId,
                        revision);
            }

            NodeList ontologyElements = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:openControlledVocabulary");
            for (int n = 0; n < ontologyElements.getLength(); n++) {
                wpRelatedCalls.addPathwayOntologyTriples(pathwayModel, pwResource, ontologyElements.item(n));
            }
            System.out.println(wpId);
            basicCalls.saveRDF2File(pathwayModel, "/tmp/" + args[0] + "/" + wpId + "_r" + revision + ".ttl",
                    "TURTLE");

            model.add(pathwayModel);
            pathwayModel.removeAll();
        }
    }
    Date myDate = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    String myDateString = sdf.format(myDate);
    FileUtils.writeStringToFile(new File("latestVersion.txt"),
            "v" + schemaVersion + "." + softwareVersion + "." + latestRevision + "_" + myDateString);
    basicCalls.saveRDF2File(model, "/tmp/wpContent_v" + schemaVersion + "." + softwareVersion + "."
            + latestRevision + "_" + myDateString + ".ttl", "TURTLE");
    basicCalls.saveRDF2File(voidModel, "/tmp/void.ttl", "TURTLE");
}

From source file:com.splicemachine.test.MiniZooKeeperCluster.java

private void prepareDir(File dir, int i) throws IOException {
    try {//from  www .j a va 2s .  com
        if (!dir.exists()) {
            dir.mkdirs();
            FileUtils.writeStringToFile(new File(dir, "myid"), "" + i);
        }
    } catch (SecurityException e) {
        throw new IOException("creating dir: " + dir, e);
    }
}

From source file:com.cedarsoft.serialization.serializers.jackson.registry.RegistrySerializerDirTest.java

License:asdf

@Before
public void setup() {
    baseDir = TestUtils.createEmptyTmpDir();

    access = new DirBasedObjectsAccess(baseDir);
    serializer = new RegistrySerializer<String, Registry<String>>(
            new DirBasedRegistrySerializingStrategy<String>(access) {
                @Nonnull//ww  w  .j av  a 2s.  c  o  m
                @Override
                protected String deserialize(@Nonnull String id, @Nonnull File dir) throws IOException {
                    return FileUtils.readFileToString(new File(dir, "data"));
                }

                @Override
                protected void serialize(@Nonnull String object, @Nonnull String id, @Nonnull File dir)
                        throws IOException {
                    File data = new File(dir, "data");
                    FileUtils.writeStringToFile(data, object);
                }
            }, new RegistrySerializer.IdResolver<String>() {
                @Override
                @Nonnull
                public String getId(@Nonnull String object) {
                    return object;
                }
            });
}

From source file:com.leclercb.taskunifier.gui.components.license.LicenseUtils.java

public static void saveLicense(String license) throws Exception {
    try {/*  w  w w . j av a2 s .c o m*/
        CheckUtils.isNotNull(license);

        license = license.trim();

        File file = new File(Main.getLicenseFile());
        FileUtils.writeStringToFile(file, license);

        LICENSE = null;

        Main.reloadProVersion();
    } catch (Exception e) {
        GuiLogger.getLogger().log(Level.SEVERE, "Cannot save license", e);
    }
}

From source file:net.nicholaswilliams.java.teamcity.plugin.linux.TestAbstractLinuxPropertiesLocator.java

@Test
public void testLocateProperties02() throws IOException {
    File pluginRoot = new File(".");
    File versionFile = new File(pluginRoot, "version.properties");
    FileUtils.writeStringToFile(versionFile, "");

    final Capture<Map<String, String>> capture = new Capture<Map<String, String>>();

    this.locator.locateLinuxProperties(capture(capture));
    expectLastCall().andAnswer(new IAnswer<Void>() {
        @Override//from w w w.  j  a  v  a  2s.com
        public Void answer() throws Throwable {
            assertTrue("The properties map should be empty.", capture.getValue().isEmpty());

            capture.getValue().put("yourLinuxProperty02", "3.9.1");

            return null;
        }
    });

    replay(this.locator);

    try {
        Map<String, String> properties = this.locator.locateProperties(pluginRoot);

        assertNotNull("The properties should not be null.", properties);
        assertEquals("The linux property is not correct.", "3.9.1", properties.get("yourLinuxProperty02"));
        assertFalse("The version property should not be present.",
                properties.containsKey(LinuxPropertiesLocator.PLUGIN_VERSION_KEY));
    } finally {
        FileUtils.forceDelete(versionFile);
    }
}

From source file:com.seleniumtests.connectors.extools.SoapUi.java

/**
 * Start SOAP UI with a project file as string. Useful when project file is stored in test resource and we only access the stream
 * @param projectString      project string
 * @param projectName      project name//from www .j a v a  2 s  . c o  m
 * @return
 */
public String executeWithProjectString(String projectString, String projectName) {
    File tmpFile;
    try {
        tmpFile = File.createTempFile("project-" + projectName, ".xml");
        FileUtils.writeStringToFile(tmpFile, projectString);
    } catch (IOException e) {
        throw new ScenarioException("Cannot write project file", e);
    }

    return executeWithProjectFile(tmpFile);
}

From source file:net.big_oh.postoffice.PostOfficeIntegrationTest.java

@Before
public void setUp() throws Exception {

    attachment1 = File.createTempFile(this.getClass().getSimpleName(), ".txt");
    FileUtils.writeStringToFile(attachment1, "first attachment");

    attachment2 = File.createTempFile(this.getClass().getSimpleName(), ".txt");
    FileUtils.writeStringToFile(attachment2, "second attachment");

    Properties postOfficeProperties = PostOfficeServiceFactory.readDefaultPostOfficeProperties();

    String smtpPassword = System.getProperty(PostOfficeServiceFactory.PROPERTY_KEY_SMTP_PASSWORD);
    assertNotNull("Failed to locate SMTP password in expected system property: "
            + PostOfficeServiceFactory.PROPERTY_KEY_SMTP_PASSWORD, smtpPassword);

    postOfficeProperties.setProperty(PostOfficeServiceFactory.PROPERTY_KEY_SMTP_PASSWORD, smtpPassword);

    postOfficeService = PostOfficeServiceFactory.getInstance(postOfficeProperties);

}