List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createGraph(String name, String outputDir, GraphCSV csv, String htmlData) throws IOException { String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/graph-curved.html")); content = content.replaceAll(Pattern.quote("$CSVNAME$"), Matcher.quoteReplacement(name)) .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData)); FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content); FileUtils.writeStringToFile(new File(outputDir + File.separator + name + ".csv"), csv.toString()); TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir); }
From source file:au.com.borner.salesforce.util.FileUtilities.java
public static boolean createLocalFile(String path, AbstractSourceCode sObject) { String fileNameWithExtension = sObject.getFullyQualifiedFileName(sObject.getName()); File localFile = new File(path + File.separator + fileNameWithExtension); double crcResult; try {//from w w w. j a v a2s . co m FileUtils.writeStringToFile(localFile, sObject.getBody()); crcResult = FileUtils.checksumCRC32(localFile); } catch (IOException e) { logger.error("Error creating file " + localFile.getPath()); return false; } if (sObject.getBodyCRC() != null && !sObject.getBodyCRC().equals(crcResult)) { logger.error("Body CRC does not match for class " + localFile.getPath()); localFile.delete(); return false; } try { createMetadataFile(path, fileNameWithExtension, sObject); } catch (Exception e) { logger.error("Error creating metadata file " + path + File.separator + fileNameWithExtension + ".sfmd", e); localFile.delete(); return false; } return true; }
From source file:de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil.java
/** * Convert Java objects into JSON format and write it to a file * * @param aObject/*from w ww. j a v a 2 s. c om*/ * the object. * @param aFile * the file * @throws IOException * if an I/O error occurs. */ public static void generateJson(MappingJacksonHttpMessageConverter jsonConverter, Object aObject, File aFile) throws IOException { FileUtils.writeStringToFile(aFile, toJsonString(jsonConverter, aObject)); }
From source file:com.ibm.web.template.generate.utils.xsd1.XmltoXSD.java
public static void convertXmlToXsd(String xmlPath, String pathToSaveXSD) throws XmlException, IOException { Inst2XsdOptions inst2XsdOptions = new Inst2XsdOptions(); inst2XsdOptions.setDesign(Inst2XsdOptions.DESIGN_RUSSIAN_DOLL); // inst2XsdOptions.setUseEnumerations(Inst2XsdOptions.ENUMERATION_NEVER); File[] xmlFiles = new File[1]; xmlFiles[0] = new File(xmlPath); XmlObject[] xmlInstance = new XmlObject[1]; xmlInstance[0] = XmlObject.Factory.parse(xmlFiles[0]); SchemaDocument[] schemaDocuments = Inst2Xsd.inst2xsd(xmlInstance, inst2XsdOptions); if (schemaDocuments != null && schemaDocuments.length > 0) { SchemaDocument schema = schemaDocuments[0]; if (pathToSaveXSD == null || pathToSaveXSD.isEmpty()) { System.out.println(schema.toString()); } else {// w ww . ja v a 2 s .c o m FileUtils.writeStringToFile(new File(pathToSaveXSD), schema.toString()); } } }
From source file:com.ricston.akka.matrix.MatrixFile.java
public static void writeMatrixFile(String filename, List<List<Double>> matrix1, List<List<Double>> matrix2, List<List<Double>> matrixResult) throws IOException { Gson gson = new GsonBuilder().setPrettyPrinting().create(); MatrixFile mF = new MatrixFile(matrix1, matrix2, matrixResult); FileUtils.writeStringToFile(new File(filename), gson.toJson(mF)); }
From source file:hudson.init.impl.InitialUserContent.java
@Initializer(after = JOB_LOADED) public static void init(Jenkins h) throws IOException { File userContentDir = new File(h.getRootDir(), "userContent"); if (!userContentDir.exists()) { userContentDir.mkdirs();/*from w ww . j a v a 2 s . c o m*/ FileUtils.writeStringToFile(new File(userContentDir, "readme.txt"), Messages.Hudson_USER_CONTENT_README()); } }
From source file:controller.EditTextEntryController.java
public void writeStringToFile(String EntryTitle, String Data) { String path = System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator + Login.getUsername() + fSeparator + "Entries" + fSeparator + EntryTitle + fSeparator + "Texts" + fSeparator + EntryTitle + ".txt"; File TextFile = new File(path); try {//from w w w .j ava 2 s .c o m FileUtils.writeStringToFile(TextFile, Data); } catch (IOException e) { } }
From source file:edu.harvard.iq.dataverse.batch.util.LoggingUtil.java
public static void saveJsonLog(String jobJson, String logDir, String jobId) { try {//from w ww .ja v a 2 s . c o m checkCreateLogDirectory(logDir); File dir = new File(logDir); if (!dir.exists() && !dir.mkdirs()) { logger.log(Level.SEVERE, "Couldn't create directory: " + dir.getAbsolutePath()); } File reportJson = new File(dir.getAbsolutePath() + "/job-" + jobId + ".json"); FileUtils.writeStringToFile(reportJson, jobJson); } catch (Exception e) { logger.log(Level.SEVERE, "Error saving json report: " + e.getMessage()); } }
From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.Features2Arff.java
@SuppressWarnings("unchecked") private static void toArffFile(Dataset dataset) throws IOException { System.out.println("Generating ARFF file"); Collection<File> files = FileUtils.listFiles(new File(FEATURES_DIR + "/" + dataset.toString()), new String[] { "txt" }, true); String arffString = toArffString(dataset, files); FileUtils.writeStringToFile(new File(MODELS_DIR + "/" + dataset.toString() + ".arff"), arffString); System.out.println(" - done"); }
From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.data.CreateVocabularyFromCorpus.java
private static void createVocabulary(Corpus corpus) throws Exception { Set<String> vocabulary = new TreeSet<String>(); for (String token : corpus.getTokens()) { vocabulary.add(token);/* w w w.ja v a 2s. c o m*/ } StringBuilder sb = new StringBuilder(); for (String item : vocabulary) { sb.append(item); sb.append(System.getProperty("line.separator")); } FileUtils.writeStringToFile(new File("target/" + corpus.getName() + ".txt"), sb.toString()); }