List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:edu.wustl.mir.erl.ihe.xdsi.util.StoreSCU.java
public boolean addFile(BufferedWriter fileInfos, File f, long endFmi, Attributes fmi, Attributes ds) throws IOException { String cuid = fmi.getString(Tag.MediaStorageSOPClassUID); String iuid = fmi.getString(Tag.MediaStorageSOPInstanceUID); String ts = fmi.getString(Tag.TransferSyntaxUID); if (cuid == null || iuid == null) return false; fileInfos.write(iuid);// w w w. java 2 s. com fileInfos.write('\t'); fileInfos.write(cuid); fileInfos.write('\t'); fileInfos.write(ts); fileInfos.write('\t'); fileInfos.write(Long.toString(endFmi)); fileInfos.write('\t'); fileInfos.write(f.getPath()); fileInfos.newLine(); if (rq.containsPresentationContextFor(cuid, ts)) return true; if (!rq.containsPresentationContextFor(cuid)) { if (relExtNeg) rq.addCommonExtendedNegotiation(relSOPClasses.getCommonExtendedNegotiation(cuid)); if (!ts.equals(UID.ExplicitVRLittleEndian)) rq.addPresentationContext(new PresentationContext(rq.getNumberOfPresentationContexts() * 2 + 1, cuid, UID.ExplicitVRLittleEndian)); if (!ts.equals(UID.ImplicitVRLittleEndian)) rq.addPresentationContext(new PresentationContext(rq.getNumberOfPresentationContexts() * 2 + 1, cuid, UID.ImplicitVRLittleEndian)); } rq.addPresentationContext(new PresentationContext(rq.getNumberOfPresentationContexts() * 2 + 1, cuid, ts)); return true; }
From source file:netinf.common.security.identity.impl.IdentityManagerImpl.java
/** * Writes all the Private Keys this IdentityManager knows to a file encrypted by a Secret Key (symmetric) * //w w w.j a v a 2s.com * @param filepath * Path to file where Private Keys shall be stored * @param algorithmUsedToEncryptTheKey * Algorithm used to encrypt the Private Key * @param password * Password used to encrypt the Private Keys * @throws NetInfCheckedException */ private void writePrivateKeysToFile(String filepath, String algorithmUsedToEncryptTheKey, String password) throws NetInfCheckedException { BufferedWriter bw; try { bw = new BufferedWriter(new FileWriter(filepath)); } catch (FileNotFoundException e) { LOG.error(e.getMessage()); throw new NetInfCheckedException(e.getMessage()); } catch (IOException e) { LOG.error(e.getMessage()); throw new NetInfCheckedException(e.getMessage()); } Iterator<Entry<String, PrivateKey>> iterator = this.privateKeys.entrySet().iterator(); while (iterator.hasNext()) { java.util.Map.Entry<String, PrivateKey> entry = iterator.next(); try { // append alias bw.write(entry.getKey()); bw.newLine(); // append algorithm used to encrypt the key bw.write(algorithmUsedToEncryptTheKey); bw.newLine(); // append algorithm key is used for bw.write(entry.getValue().getAlgorithm()); bw.newLine(); // append encrypted private key String encryptedPrivateKey = this.cryptoAlgorithm.encryptPrivateKey(algorithmUsedToEncryptTheKey, this.cryptoAlgorithm.getSecretKeyFromString(algorithmUsedToEncryptTheKey, password), entry.getValue()); char[] encryptedPrivateKeyChars = encryptedPrivateKey.toCharArray(); for (int i = 0; i < encryptedPrivateKeyChars.length; i++) { bw.write("" + ((int) encryptedPrivateKeyChars[i])); bw.newLine(); } bw.write("END OF KEY"); bw.newLine(); } catch (IOException e) { LOG.warn("PrivateKey couldn't be saved to file. " + e.getMessage()); } finally { try { bw.flush(); } catch (IOException e) { LOG.warn("Error writing to file. " + e.getMessage()); throw new NetInfCheckedException("Error writing to file."); } } } try { bw.close(); } catch (IOException e) { LOG.warn("Unable to close file. " + e.getMessage()); throw new NetInfCheckedException("Unable to close file."); } }
From source file:com.redsqirl.workflow.server.ActionManager.java
public void packageNotified(Collection<String> packageNames) { File footerPackageNotificationFile = new File(WorkflowPrefManager.getPathFooterPackageNotification()); BufferedWriter bw = null; try {//from ww w .j a v a 2 s. c om if (footerPackageNotificationFile.exists()) { bw = new BufferedWriter(new FileWriter(footerPackageNotificationFile, true)); } else { bw = new BufferedWriter(new FileWriter(footerPackageNotificationFile)); } Iterator<String> it = packageNames.iterator(); while (it.hasNext()) { String cur = it.next(); bw.write(cur); bw.newLine(); } bw.close(); } catch (Exception e) { logger.error("Error while reading class file", e); footerPackageNotificationFile.delete(); } }
From source file:com.google.code.maven.plugin.http.client.transformer.JiraRssLinkedIssuesEnricher.java
private void enrich(final BufferedWriter writer, final HashSet<String> linkedIssues, final int depth) throws ClientProtocolException, IOException { // removes duplicates for (String jira : rssIssues) { linkedIssues.remove(jira);//from www.java 2s. c o m } // request for jira missing in the rss for (final String issue : linkedIssues) { remaining.incrementAndGet(); asyncTaskExecutor.execute(new Runnable() { public void run() { try { rssIssues.add(issue); String content = queryForJira(issue); if (content != null) { synchronized (writer) { writer.write(content); writer.newLine(); writer.flush(); } log.warn("issue [" + issue + "] added"); if (depth > 0) { enrich(writer, inspectItem(content), depth - 1); } } else { log.warn("issue [" + issue + "] not found"); } } catch (MojoExecutionException e) { log.warn("issue [" + issue + "] not found"); } catch (ClientProtocolException e) { log.warn("issue [" + issue + "] not found"); } catch (IOException e) { log.warn("issue [" + issue + "] not found"); } remaining.decrementAndGet(); } }); } }
From source file:io.siddhi.extension.io.file.FileSourceRegexModeTestCase.java
@Test public void siddhiIoFileTest8() throws InterruptedException { log.info("test SiddhiIoFile [mode = regex] 8"); String streams = "" + "@App:name('TestSiddhiApp')" + "@source(type='file', mode='regex'," + "dir.uri='file:/" + dirUri + "/regex/xml', " + "begin.regex='(<events>)', " + "end.regex='(</events>)', " + "tailing='true', " + "@map(type='xml'))" + "define stream FooStream (symbol string, price float, volume long); " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("BarStream", new StreamCallback() { @Override//from ww w . j ava2s . c o m public void receive(Event[] events) { EventPrinter.print(events); int n = count.incrementAndGet(); for (Event event : events) { switch (n) { case 1: AssertJUnit.assertEquals(10000L, event.getData(2)); break; case 2: AssertJUnit.assertEquals(10001L, event.getData(2)); break; case 3: AssertJUnit.assertEquals(10002L, event.getData(2)); break; case 4: AssertJUnit.assertEquals(10003L, event.getData(2)); break; case 5: AssertJUnit.assertEquals(10004L, event.getData(2)); break; case 6: AssertJUnit.assertEquals(1000L, event.getData(2)); break; case 7: AssertJUnit.assertEquals(2000L, event.getData(2)); break; default: AssertJUnit.fail("More events received than expected."); } } } }); Thread t1 = new Thread(new Runnable() { public void run() { siddhiAppRuntime.start(); } }); t1.start(); SiddhiTestHelper.waitForEvents(waitTime, 5, count, timeout); Thread t2 = new Thread(new Runnable() { @Override public void run() { File file = new File(dirUri + "/regex/xml/xml_logs (3rd copy).txt"); try { StringBuilder sb = new StringBuilder(); sb.append("<events>\n").append("<event>\n").append("<symbol>").append("GOOGLE") .append("</symbol>\n").append("<price>").append("100").append("</price>\n") .append("<volume>").append("1000").append("</volume>\n").append("</event>\n") .append("</events>\n"); sb.append("<events>\n").append("<event>\n").append("<symbol>").append("YAHOO") .append("</symbol>\n").append("<price>").append("200").append("</price>\n") .append("<volume>").append("2000").append("</volume>\n").append("</event>\n") .append("</events>\n"); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, true)); bufferedWriter.write(sb.toString()); bufferedWriter.newLine(); bufferedWriter.flush(); bufferedWriter.close(); } catch (IOException e) { log.error(e.getMessage()); } } }); t2.start(); SiddhiTestHelper.waitForEvents(waitTime, 7, count, timeout); //assert event count AssertJUnit.assertEquals("Number of events", 7, count.get()); siddhiAppRuntime.shutdown(); }
From source file:com.idega.slide.webdavservlet.DomainConfig.java
private void replaceConfigfileStream(InputStream configInputStream, Writer targetOut, FilterChain filterChain) throws IOException { BufferedReader in = null;/*from w w w . j a va2 s. c o m*/ BufferedWriter out = null; try { ChainReaderHelper helper = new ChainReaderHelper(); helper.setBufferSize(8192); helper.setPrimaryReader(new BufferedReader(new InputStreamReader(configInputStream))); Vector filterChains = new Vector(); filterChains.add(filterChain); helper.setFilterChains(filterChains); in = new BufferedReader(helper.getAssembledReader()); out = new BufferedWriter(targetOut); String line; while ((line = in.readLine()) != null) { if (line.length() == 0) { out.newLine(); } else { out.write(line); out.newLine(); } } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
From source file:org.apache.playframework.generator.mybatisplus.AutoGenerator.java
/** * XML/* ww w . jav a 2 s . com*/ * * @param beanName * @param columns * @param types * @param comments * @throws IOException */ protected void buildMapperXml(String beanName, List<String> columns, List<String> types, List<String> comments, Map<String, IdInfo> idMap, String mapperName, String mapperXMLName) throws IOException { File mapperXmlFile = new File(PATH_XML, mapperXMLName + ".xml"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperXmlFile))); bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); bw.newLine(); bw.write( "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">"); bw.newLine(); bw.write("<mapper namespace=\"" + config.getMapperPackage() + "." + mapperName + "\">"); bw.newLine(); bw.newLine(); /* * ?SqlMapper */ if (config.isResultMap()) { buildResultMap(bw, beanName, idMap, columns); } else { buildSQL(bw, idMap, columns); } bw.write("</mapper>"); bw.flush(); bw.close(); }
From source file:org.apache.playframework.generator.mybatisplus.AutoGenerator.java
/** * Mapper// ww w . j av a 2s . c o m * * @param beanName * @param mapperName * @throws IOException */ protected void buildMapper(String beanName, String mapperName) throws IOException { File mapperFile = new File(PATH_MAPPER, mapperName + ".java"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mapperFile), "utf-8")); bw.write("package " + config.getMapperPackage() + ";"); bw.newLine(); bw.newLine(); bw.write("import " + config.getEntityPackage() + "." + beanName + ";"); bw.newLine(); bw.write("import com.baomidou.mybatisplus.mapper.BaseMapper;"); bw.newLine(); bw = buildClassComment(bw, beanName + " ??"); bw.newLine(); bw.write("public interface " + mapperName + " extends BaseMapper<" + beanName + "> {"); bw.newLine(); bw.newLine(); // ----------mapperEnd---------- bw.newLine(); bw.write("}"); bw.flush(); bw.close(); }
From source file:org.apache.playframework.generator.mybatisplus.AutoGenerator.java
/** * Controller//from w w w . j av a 2 s .com * * @param beanName * @param controllerName * @throws IOException */ protected void buildController(String beanName, String controllerName) throws IOException { File serviceFile = new File(PATH_CONTROLLER_IMPL, controllerName + ".java"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serviceFile), "utf-8")); bw.write("package " + config.getControllerPackage() + ";"); bw.newLine(); bw.newLine(); bw.write("import org.springframework.stereotype.Controller;"); bw.newLine(); bw = buildClassComment(bw, beanName + " "); bw.newLine(); bw.write("@Controller"); bw.newLine(); bw.write("public class " + controllerName + " {"); bw.newLine(); bw.newLine(); bw.newLine(); bw.write("}"); bw.flush(); bw.close(); }
From source file:lenscorrection.Distortion_Correction.java
public void evaluateCorrection(final List<List<PointMatch>> inliers) { IJ.showStatus("Evaluating Distortion Correction"); final double[][] original = new double[sp.numberOfImages][2]; final double[][] corrected = new double[sp.numberOfImages][2]; for (int i = sp.firstImageIndex; i < sp.numberOfImages; i++) { original[i] = evaluateCorrectionXcorr(i, sp.source_dir); corrected[i] = evaluateCorrectionXcorr(i, sp.target_dir); }/* ww w. jav a 2s . com*/ final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final DefaultCategoryDataset datasetGain = new DefaultCategoryDataset(); final DefaultCategoryDataset datasetGrad = new DefaultCategoryDataset(); for (int i = 0; i < (original.length); ++i) { dataset.setValue(Math.abs(original[i][0]), "before", "image" + i); dataset.setValue(Math.abs(corrected[i][0]), "after", "image" + i); datasetGrad.setValue(Math.abs(original[i][1]), "before", "image" + i); datasetGrad.setValue(Math.abs(corrected[i][1]), "after", "image" + i); datasetGain.setValue(Math.abs(corrected[i][0]) - Math.abs(original[i][0]), "gray", "image" + i); datasetGain.setValue(Math.abs(corrected[i][1]) - Math.abs(original[i][1]), "grad", "image" + i); } final JFreeChart chart = ChartFactory.createBarChart("Xcorr before and after correction", "ImageNumber", "Xcorr", dataset, PlotOrientation.VERTICAL, false, true, false); final ImagePlus imp = new ImagePlus("Xcorr before and after correction Plot", chart.createBufferedImage(500, 300)); imp.show(); final JFreeChart chartGrad = ChartFactory.createBarChart("XcorrGradient before and after correction", "ImageNumber", "Xcorr", datasetGrad, PlotOrientation.VERTICAL, false, true, false); final ImagePlus impGrad = new ImagePlus("XcorrGradient before and after correction Plot", chartGrad.createBufferedImage(500, 300)); impGrad.show(); final JFreeChart chartGain = ChartFactory.createBarChart("Gain in Xcorr", "ImageNumber", "Xcorr", datasetGain, PlotOrientation.VERTICAL, false, true, false); final ImagePlus impGain = new ImagePlus("Gain in Xcorr Plot", chartGain.createBufferedImage(500, 300)); impGain.show(); visualizePoints(inliers); //write xcorr data to file String original0 = "", original1 = "", corrected0 = "", corrected1 = "", gain0 = "", gain1 = ""; for (int i = 0; i < (original.length); ++i) { original0 = original0 + Double.toString(original[i][0]) + "; "; original1 = original1 + Double.toString(original[i][1]) + "; "; corrected0 = corrected0 + Double.toString(corrected[i][0]) + "; "; corrected1 = corrected1 + Double.toString(corrected[i][1]) + "; "; gain0 = gain0 + Double.toString(Math.abs(corrected[i][0]) - Math.abs(original[i][0])) + "; "; gain1 = gain1 + Double.toString(Math.abs(corrected[i][1]) - Math.abs(original[i][1])) + "; "; } try { final BufferedWriter out = new BufferedWriter(new FileWriter(sp.source_dir + "xcorrData.log")); out.write(original0); out.newLine(); out.newLine(); out.write(original1); out.newLine(); out.newLine(); out.write(corrected0); out.newLine(); out.newLine(); out.write(corrected1); out.newLine(); out.newLine(); out.write(gain0); out.newLine(); out.newLine(); out.write(gain1); out.newLine(); out.close(); } catch (final Exception e) { System.err.println("Error: " + e.getMessage()); } ; }