List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:net.estinet.gFeatures.Feature.CTF.Confligs.ConfligInit.java
public void MakeFile(String filename) throws IOException { Reader paramReader = new InputStreamReader(getClass().getResourceAsStream(filename + ".yml")); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer);/* ww w .j a v a2 s .c om*/ String theString = writer.toString(); File f = new File("plugins/CrackShot/weapons/" + filename + ".yml"); f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); bw.write(theString); bw.close(); }
From source file:com.cloudera.csd.tools.MetricTools.java
/** * Writes usage message to 'stream'.//w w w. ja v a2 s.co m * * @param stream output stream. * @throws UnsupportedEncodingException */ public static void printUsageMessage(OutputStream stream) throws UnsupportedEncodingException { PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream, "UTF-8"))); try { String header = "Cloudera Manager Metric Tools"; String footer = ""; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, "metric tools", header, OPTIONS, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer, true); // auto-usage: whether to also show // the command line args on the usage line. } finally { writer.close(); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SetTermsListener.java
@Override public void handleEvent(Event event) { // TODO Auto-generated method stub File file = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".words.tmp"); try {// w ww .ja va2 s . c o m FileWriter fw = new FileWriter(file); BufferedWriter out = new BufferedWriter(fw); out.write("Filename\tColumn Number\tOriginal Data Value\tNew Data Value\n"); // HashMap<String, Vector<String>> oldValues = this.setTermsUI.getOldValues(); HashMap<String, Vector<String>> newValues = this.setTermsUI.getNewValues(); for (String fullName : oldValues.keySet()) { File rawFile = new File(this.dataType.getPath() + File.separator + fullName.split(" - ", -1)[0]); String header = fullName.split(" - ", -1)[1]; int columnNumber = FileHandler.getHeaderNumber(rawFile, header); for (int i = 0; i < oldValues.get(fullName).size(); i++) { if (newValues.get(fullName).elementAt(i).compareTo("") != 0) { out.write(rawFile.getName() + "\t" + columnNumber + "\t" + oldValues.get(fullName).elementAt(i) + "\t" + newValues.get(fullName).elementAt(i) + "\n"); } } } out.close(); try { File fileDest; if (((ClinicalData) this.dataType).getWMF() != null) { String fileName = ((ClinicalData) this.dataType).getWMF().getName(); ((ClinicalData) this.dataType).getWMF().delete(); fileDest = new File(this.dataType.getPath() + File.separator + fileName); } else { fileDest = new File(this.dataType.getPath() + File.separator + this.dataType.getStudy().toString() + ".words"); } FileUtils.moveFile(file, fileDest); ((ClinicalData) this.dataType).setWMF(fileDest); } catch (IOException ioe) { this.setTermsUI.displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.setTermsUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } this.setTermsUI.displayMessage("Word mapping file updated"); WorkPart.updateSteps(); WorkPart.updateFiles(); UsedFilesPart.sendFilesChanged(dataType); }
From source file:com.lianggzone.freemarkerutils.utils.FreeMarkerFactory.java
/** * ?ftl?,???HTML/* w w w .jav a2 s .com*/ * @param ftlPath FTL?,["c:/liang/template.ftl"] * @param filePath ?HMTL["d:/liang/lianggzone.html"] * @param data Map? * @param isCreate4NoExists ?? * @return */ public static boolean createHTML(String ftlPath, String filePath, Map<String, Object> data, boolean isCreate4NoExists) throws IOException { String fileDir = StringUtils.substringBeforeLast(filePath, "/"); // ?HMTL // String fileName = StringUtils.substringAfterLast(filePath, "/"); // ?HMTL?? String ftlDir = StringUtils.substringBeforeLast(ftlPath, "/"); // ?FTL String ftlName = StringUtils.substringAfterLast(ftlPath, "/"); // ?FTL?? //? if (isCreate4NoExists) { File realDirectory = new File(fileDir); if (!realDirectory.exists()) { realDirectory.mkdirs(); } } // step1 ?freemarker? Configuration freemarkerCfg = new Configuration(Configuration.VERSION_2_3_23); // step2 freemarker??() freemarkerCfg.setDirectoryForTemplateLoading(new File(ftlDir)); // step3 freemarker?? freemarkerCfg.setEncoding(Locale.getDefault(), CharEncoding.UTF_8); // step4 freemarker? Template template = freemarkerCfg.getTemplate(ftlName, CharEncoding.UTF_8); // step5 ?IO? try (Writer writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(new File(filePath)), CharEncoding.UTF_8))) { writer.flush(); // step6 ?? template.process(data, writer); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:com.salsaberries.narchiver.Writer.java
/** * Writes all the pages to file.//w w w.j a v a 2 s .c o m * * @param pages * @param location */ public static void storePages(LinkedList<Page> pages, String location) { logger.info("Dumping " + pages.size() + " pages to file at " + location + "/"); File file = new File(location); // Make sure the directory exists if (!file.exists()) { try { file.mkdirs(); logger.info("Directory " + file.getAbsolutePath() + " does not exist, creating."); } catch (SecurityException e) { logger.error(e.getMessage()); } } // Write them to the file if they haven't been already written while (!pages.isEmpty()) { Page page = pages.removeFirst(); String fileName = file.getAbsolutePath() + "/" + page.getDate() + "|" + URLEncoder.encode(page.getTagURL()); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write(page.toString()); } catch (IOException e) { logger.warn(e.getMessage()); } // Temporarily try to reduce memory page.setHtml(""); } }
From source file:com.linkedin.pinot.tools.segment.converter.PinotSegmentToCsvConverter.java
@Override public void convert() throws Exception { PinotSegmentRecordReader recordReader = new PinotSegmentRecordReader(new File(_segmentDir)); try {/* www.j a v a2s . c o m*/ recordReader.init(); try (BufferedWriter recordWriter = new BufferedWriter(new FileWriter(_outputFile))) { if (_withHeader) { GenericRow row = recordReader.next(); recordWriter.write(StringUtils.join(row.getFieldNames(), _delimiter)); recordWriter.newLine(); recordReader.rewind(); } while (recordReader.hasNext()) { GenericRow row = recordReader.next(); String[] fields = row.getFieldNames(); List<String> record = new ArrayList<>(fields.length); for (String field : fields) { Object value = row.getValue(field); if (value instanceof Object[]) { record.add(StringUtils.join((Object[]) value, _listDelimiter)); } else { record.add(value.toString()); } } recordWriter.write(StringUtils.join(record, _delimiter)); recordWriter.newLine(); } } } finally { recordReader.close(); } }
From source file:net.sbfmc.modules.anticheat.conf.AnticheatReportsNicksConf.java
@Override public void savePlayer(PlayerSession sessionRaw) throws IOException { AnticheatPlayerSession session = (AnticheatPlayerSession) sessionRaw; File file = new File(confFolder, session.getPlayer().getName() + ".txt"); BufferedWriter buffW = new BufferedWriter(new FileWriter(file, true)); buffW.write("-----\n"); buffW.write("ReportMode=1\n"); buffW.write("Name=" + session.getPlayer().getName() + "\n"); buffW.write("IP=" + session.getPlayer().getPlayer().getAddress().getAddress().getHostAddress() + "\n"); buffW.write("Date=" + new SimpleDateFormat("dd-MM-yy HH:mm").format(new Date()) + "\n"); for (String s : session.getOtherNicks()) { buffW.write(s + "\n"); }//from w w w .j a v a2s . co m buffW.close(); }
From source file:com.nextep.designer.beng.model.impl.FileUtils.java
/** * Writes the specified contents to a file at the given file location. * //from w w w .ja v a 2 s . c o m * @param fileName name of the file to create (will be replaced if exists) * @param contents contents to write to the file. */ public static void writeToFile(String fileName, String contents) { // Retrieves the encoding specified in the preferences String encoding = SQLGenUtil.getPreference(PreferenceConstants.SQL_SCRIPT_ENCODING); final boolean convert = SQLGenUtil.getPreferenceBool(PreferenceConstants.SQL_SCRIPT_NEWLINE_CONVERT); if (convert) { String newline = CorePlugin.getService(IGenerationService.class).getNewLine(); // Converting everything to \n then \n to expected new line contents = contents.replace("\r\n", "\n"); contents = contents.replace("\r", "\n"); contents = contents.replace("\n", newline); } Writer w = null; try { w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(fileName)), encoding)); w.write(contents); } catch (FileNotFoundException e) { throw new ErrorException(e); } catch (IOException e) { throw new ErrorException(e); } finally { if (w != null) { try { w.close(); } catch (IOException e) { throw new ErrorException(e); } } } }
From source file:jt56.comm.code.util.CommonPageParser.java
public static void WriterPage(VelocityContext context, String templateName, String fileDirPath, String targetFile) {/* w w w .ja v a2 s.co m*/ try { File file = new File(fileDirPath + targetFile); if (!(file.exists())) { new File(file.getParent()).mkdirs(); } else if (isReplace) { log.info("?:" + file.getAbsolutePath()); } Template template = ve.getTemplate(templateName, "UTF-8"); FileOutputStream fos = new FileOutputStream(file); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); template.merge(context, writer); writer.flush(); writer.close(); fos.close(); log.info("?" + file.getAbsolutePath()); } catch (Exception e) { log.error(e); } }
From source file:graph.module.cli.ManualDisjointnessCommand.java
@Override protected void executeImpl() { if (data.isEmpty()) { printErrorNoData();//w w w. j av a2 s .c o m return; } // If file, load the file, iterate through it, and output to file. ArrayList<String> split = UtilityMethods.split(data, ' '); DirectedAcyclicGraph dag = ((DAGPortHandler) handler).getDAG(); try { OUTPUT_FILE.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(OUTPUT_FILE)); if (split.size() == 1) { File file = new File(split.get(0)); if (!file.exists()) { print("-1|Cannot find file.\n"); out.close(); return; } BufferedReader in = new BufferedReader(new FileReader(file)); String input = null; ArrayList<String> inputs = new ArrayList<>(); while ((input = in.readLine()) != null) { if (!input.startsWith("@")) { inputs.add(input); } else { out.write(input + "\n"); } } in.close(); // Shuffle and process Collections.shuffle(inputs); int i = 1; for (String line : inputs) { String[] elements = line.split(","); if (!printResult(elements[0], elements[1], dag, out, i++, inputs.size())) break; } } else if (split.size() == 2) { // If inputs, process, and output to file. printResult(split.get(0), split.get(1), dag, out, 1, 1); } out.close(); } catch (Exception e) { print("-1|Exception!\n"); return; } }