List of usage examples for java.io FileWriter FileWriter
public FileWriter(FileDescriptor fd)
From source file:gov.nih.nci.caarray.plugins.agilent.EndOfLineCorrectingReaderTest.java
private File createTestFile() throws IOException { File file = File.createTempFile("EndOfLineCorrectingReaderTest", null); file.deleteOnExit();//from w ww.j ava2 s .c o m final FileWriter fileWriter = new FileWriter(file); try { IOUtils.copy(new StringReader(originalData), fileWriter); } finally { fileWriter.close(); } return file; }
From source file:com.shazam.fork.listeners.RawLogCatWriter.java
@Override public void writeLogs(TestIdentifier test, List<LogCatMessage> logCatMessages) { File file = fileManager.createFile(RAW_LOG, pool, serial, test); FileWriter fileWriter = null; try {/*from w ww . j a v a2 s . com*/ fileWriter = new FileWriter(file); for (LogCatMessage logCatMessage : logCatMessages) { write(logCatMessage.toString(), fileWriter); write("\n", fileWriter); } } catch (IOException e) { throw new RuntimeException(e); } finally { closeQuietly(fileWriter); } }
From source file:test.gov.nih.nci.system.web.client.HardDriveClient.java
private static File marshall(HardDrive hardDrive) throws IOException, XMLUtilityException { String namespacePrefix = "gme://caCORE.caCORE/3.2/"; String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetomany.bidirectional"; Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix); Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName); XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller); File myFile = new File("HardDrive.xml"); FileWriter myWriter = new FileWriter(myFile); myUtil.toXML(hardDrive, myWriter);/* w w w . ja v a2 s . c o m*/ myWriter.close(); return myFile; }
From source file:de.ipbhalle.metfrag.main.CommandLineTool.java
/** * @param args//ww w . j ava 2 s . com * @throws Exception */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption("d", "database", true, "database: " + Databases.getString() + " (default: kegg)"); options.addOption("l", "localdb", true, "use a local database together with a settings file for candidate search (default: not used) note: only usable if pubchem database is selected (-d)"); options.addOption("a", "mzabs", true, "allowed absolute (Da) mass deviation of fragment and peak masses (default: 0.01)"); options.addOption("p", "mzppm", true, "allowed relative (ppm) mass deviation of fragment and peak masses (default: 10)"); options.addOption("s", "searchppm", true, "relative (ppm) mass deviation used for candidate search in given compound database (-d) (default: 10; not used by default if sdf database is selected (-d))\n"); options.addOption("n", "exactmass", true, "neutral mass of measured compound used for candidate search in database (-d) (mandatory)"); options.addOption("b", "biological", false, "only consider compounds including CHNOPS atoms (not used by default)"); options.addOption("i", "databaseids", true, "database ids of compounds used for in silico fragmentation (separated by ,) (not used by default; not used if sdf database is selected (-d)) note: given ids must be valid ids of given database (-d)"); options.addOption("t", "treedepth", true, "treedepth used for in silico fragmentation (default: 2) note: high values result in high computation time"); options.addOption("M", "mode", true, "mode used for measured ms/ms spectrum:\n" + Modes.getString() + "(default: 3)"); options.addOption("f", "formula", true, "molecular formula of measured compound used for candidate search in database (-d) (not used by default; not used if sdf database is selected (-d))"); options.addOption("B", "breakrings", false, "allow splitting of aromatic rings of candidate structures during in silico fragmentation (not used by default)"); options.addOption("F", "storefragments", false, "store in silico generated fragments of candidate molecules (not used by default)"); options.addOption("R", "resultspath", true, "directory where result files are stored (default: /tmp)"); options.addOption("L", "sdffile", true, "location of the local sdf file (mandatory if sdf database (-d) is selected)"); options.addOption("h", "help", false, "print help"); options.addOption("D", "spectrumfile", true, "file containing peak data (mandatory) note: commandline options overwrite parameters given in the spectrum data file"); options.addOption("T", "threads", true, "number of threads used for fragment calculation (default: number of available cpu cores)"); options.addOption("c", "chemspidertoken", true, "Token for ChemSpider database search (not used by default; only necessary (mandatory) if ChemSpider database (-d) is selected)"); options.addOption("v", "verbose", false, "get more output information during the processing (not used by default)"); options.addOption("S", "samplename", true, "name of the sample measured (mandatory) note: result files are stored with given value"); options.addOption("P", "saveparameters", false, "save used parameters (not used by default)"); options.addOption("e", "printexamplespecfile", false, "print an example spectrum data file (not used by default)"); options.addOption("C", "charge", true, "charge used in combination with mode (-M):\n" + Charges.getString() + " (default: 1)"); options.addOption("r", "range", true, "range of candidates that will be processed: N (first N), M-N (from M to N), M- (from M), -N (till N); if N is greater than the number of candidates it will be set accordingly"); // parse the command line arguments CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException e1) { System.out.println(e1.getMessage()); System.out.println("Error: Could not parse option parameters."); System.out.println("Use help -h (--help) for information."); System.exit(1); } if (line == null) { System.out.println("Error: Could not parse option parameters."); System.out.println("Use help -h (--help) for information."); System.exit(1); } if (checkInitialParamsPresent(line, options)) System.exit(0); if (!checkSpectrumFile(line)) { System.out.println("Error: Option parameters are not set correctly."); System.out.println("Use help -h (--help) for information."); System.exit(1); } if (!parseSpectrumFile(spectrumfile)) { System.out.println("Error: Could not correctly parse the spectrum data file."); System.out.println("Use help -h (--help) for information."); System.exit(1); } int successfulSet = setParameters(line, options); if (successfulSet == 2) System.exit(0); if (successfulSet != 0) { System.out.println("Error: Option parameters are not set correctly."); System.out.println("Use help -h (--help) for information."); System.exit(1); } boolean successfulChecked = true; if (successfulSet == 0) successfulChecked = checkParameters(); if (saveParametersIsSet) { try { BufferedWriter bwriter = new BufferedWriter(new FileWriter(new File( resultspath + System.getProperty("file.separator") + "parameters_" + sampleName + ".txt"))); bwriter.write(getParameters()); bwriter.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { boolean isPositive = true; if (charge.getValue() == 2) isPositive = false; spec = new WrapperSpectrum(peaksString, mode.getValueWithOffset(), exactMass.getValue(), isPositive); } catch (Exception e) { System.out.println("Error: Could not parse spectrum correctly. Check the given peak list."); System.exit(1); } if (!successfulChecked) { System.out.println("Error: Option parameters are not set correctly."); System.out.println("Use help -h (--help) for information."); System.exit(1); } List<MetFragResult> results = null; String pathToStoreFrags = ""; if (storeFragments) pathToStoreFrags = resultspath; //run metfrag when all checks were successful if (usesdf) { try { if (verbose) { System.out.println("start fragmenter with local database"); System.out.println("using database " + database); } results = MetFrag.startConvenienceSDF(spec, mzabs.getValue(), mzppm.getValue(), searchppm.getValue(), true, breakRings, treeDepth.getValue(), true, true, true, false, Integer.MAX_VALUE, true, sdfFile, "", null, searchppmIsSet, pathToStoreFrags, numberThreads.getValue(), verbose, sampleName, onlyBiologicalCompounds); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); System.out.println("Error: Could not perform in silico fragmentation step."); System.exit(1); } } else { try { if (verbose) { if (!localdbIsSet) System.out.println("start fragmenter with web database"); else System.out.println("start fragmenter with local database"); System.out.println("using database " + database); } results = MetFrag.startConvenience(database, databaseIDs, formula, exactMass.getValue(), spec, useProxy, mzabs.getValue(), mzppm.getValue(), searchppm.getValue(), true, breakRings, treeDepth.getValue(), true, false, true, false, startindex.getValue(), endindex.getValue(), true, pathToStoreFrags, numberThreads.getValue(), chemSpiderToken, verbose, sampleName, localdb, onlyBiologicalCompounds, dblink, dbuser, dbpass, uniquebyinchi); } catch (Exception e) { e.printStackTrace(); System.out.println("Error: " + e.getMessage()); System.out.println("Error: Could not perform in silico fragmentation step."); System.exit(1); } } saveResults(results); }
From source file:io.proleap.cobol.TestGenerator.java
public static void generateTestClass(final File cobolInputFile, final File outputDirectory, final String packageName) throws IOException { final File parentDirectory = cobolInputFile.getParentFile(); final String inputFilename = getInputFilename(cobolInputFile); final File outputFile = new File( outputDirectory + "/" + inputFilename + OUTPUT_FILE_SUFFIX + JAVA_EXTENSION); final boolean createdNewFile = outputFile.createNewFile(); if (createdNewFile) { LOG.info("Creating unit test {}.", outputFile); final PrintWriter pWriter = new PrintWriter(new FileWriter(outputFile)); final String cobolInputFileName = cobolInputFile.getPath().replace("\\", "/"); final CobolSourceFormat format = getCobolSourceFormat(parentDirectory); pWriter.write("package " + packageName + ";\n"); pWriter.write("\n"); pWriter.write("import java.io.File;\n"); pWriter.write("\n"); pWriter.write("import io.proleap.cobol.applicationcontext.CobolGrammarContextFactory;\n"); pWriter.write("import io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum;\n"); pWriter.write("import io.proleap.cobol.runner.CobolParseTestRunner;\n"); pWriter.write("import io.proleap.cobol.runner.impl.CobolParseTestRunnerImpl;\n"); pWriter.write("import org.junit.Test;\n"); pWriter.write("\n"); pWriter.write("public class " + inputFilename + "Test {\n"); pWriter.write("\n"); pWriter.write(" @Test\n"); pWriter.write(" public void test() throws Exception {\n"); pWriter.write(" CobolGrammarContextFactory.configureDefaultApplicationContext();\n"); pWriter.write("\n"); pWriter.write(" final File inputFile = new File(\"" + cobolInputFileName + "\");\n"); pWriter.write(" final CobolParseTestRunner runner = new CobolParseTestRunnerImpl();\n"); pWriter.write(" runner.parseFile(inputFile, CobolSourceFormatEnum." + format + ");\n"); pWriter.write(" }\n"); pWriter.write("}"); pWriter.flush();//from w ww . j a v a2 s .c om pWriter.close(); } }
From source file:com.amazonaws.util.FileUtils.java
/** * Appends the given data to the file specified in the input and returns the * reference to the file./*w ww. j a v a 2 s. c o m*/ * * @param file * @param dataToAppend * @return reference to the file. * @throws IOException */ public static File appendDataToTempFile(File file, String dataToAppend) throws IOException { FileWriter outputWriter = new FileWriter(file); try { outputWriter.append(dataToAppend); } finally { outputWriter.close(); } return file; }
From source file:com.wso2telco.services.bw.FileUtil.java
public static void fileWrite(String filePath, String data) throws IOException { BufferedWriter out = null;//from ww w . j av a 2 s . c om try { out = new BufferedWriter(new FileWriter(filePath)); out.write(data); } catch (IOException e) { e.printStackTrace(); } finally { out.close(); } }
From source file:WarUtil.java
private static void writeLastModifiled(File file, long time) { BufferedWriter writer = null; try {//from w w w . ja va 2 s . co m if (!file.exists()) { file.createNewFile(); } writer = new BufferedWriter(new FileWriter(file)); writer.write(Long.toString(time)); writer.flush(); } catch (Exception e) { } }
From source file:com.spike.tg4w.htmlunit.XmlTestResultImpl.java
public XmlTestResultImpl(String filename, String encoding) throws IOException { this.writer = new FileWriter(filename); if (encoding == null) { encoding = "ISO-8859-1"; }/*from w ww . ja va 2 s . c om*/ write("<?xml version='1.0' encoding='" + encoding + "'?>"); write("<tests>"); this.writeDir = (new File(filename)).getParent(); Runtime.getRuntime().addShutdownHook(new ShutDownHook(this)); }
From source file:biz.c24.batchdemo.writers.SplittingFileWriterSource.java
@Override public void initialise(StepExecution stepExecution) { // Extract the name of the file we're supposed to be writing to String fileName = stepExecution.getJobParameters().getString("output.file"); // Remove any leading file:// if it exists if (fileName.startsWith("file://")) { fileName = fileName.substring("file://".length()); }//from ww w .j a v a 2s .c om try { outputFile = new FileWriter(fileName); } catch (IOException ioEx) { throw new RuntimeException(ioEx); } }