List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:com.funambol.pushlistener.example.DummyRandomSubmitterLogParser.java
private void dumpEvent(Event event, BufferedWriter writer) throws Exception { writer.write(event.toLine());//from w ww . ja va 2 s. c o m writer.newLine(); writer.flush(); }
From source file:com.ontheserverside.batch.bank.tx.SimpleElixir0Generator.java
@Override public void generate(final File outputFile, final int numberOfTransactions) throws IOException { final TxGenerator txGenerator = new TxGenerator(); final BufferedWriter writer = Files.newBufferedWriter(outputFile.toPath(), StandardCharsets.UTF_8); try {/*www . ja va2 s . co m*/ for (int i = 0; i < numberOfTransactions; i++) { writer.write(txGenerator.generate().toString()); writer.newLine(); } } finally { writer.close(); } }
From source file:de.clusteval.data.dataset.generator.Gaussian2DDataSetGenerator.java
@Override protected GoldStandard generateGoldStandard() throws GoldStandardGenerationException { try {/* w w w. jav a2 s.c o m*/ // goldstandard file File goldStandardFile = new File(FileUtils.buildPath(this.repository.getBasePath(GoldStandard.class), this.getFolderName(), this.getFileName())); BufferedWriter writer = new BufferedWriter(new FileWriter(goldStandardFile)); for (int row = 0; row < classes.length; row++) { writer.append((row + 1) + "\t" + classes[row] + ":1.0"); writer.newLine(); } writer.close(); return new GoldStandard(repository, goldStandardFile.lastModified(), goldStandardFile); } catch (IOException e) { e.printStackTrace(); } catch (RegisterException e) { e.printStackTrace(); } throw new GoldStandardGenerationException("The goldstandard could not be generated!"); }
From source file:fr.itinerennes.onebusaway.bundle.tasks.GenerateRoutesAndStopsCsvTask.java
/** * {@inheritDoc}/*from w w w . j av a 2 s.c o m*/ * * @see java.lang.Runnable#run() */ @Override public void run() { @SuppressWarnings("unchecked") final Map<String, Set<String>> routesToStops = LazyMap.decorate(new HashMap<String, Set<String>>(), new Factory() { @Override public Object create() { return new HashSet<String>(); } }); for (final StopTime stopTime : gtfsDao.getAllStopTimes()) { final String routeId = stopTime.getTrip().getRoute().getId().toString(); final String stopId = stopTime.getStop().getId().toString(); // add or overwrite stopId for the routeId routesToStops.get(routeId).add(stopId); } // count amount of couples (routeId, stopId) int count = 0; for (final Entry<String, Set<String>> route : routesToStops.entrySet()) { if (route.getValue().isEmpty()) { throw new IllegalStateException("route " + route.getKey() + " has 0 stops"); } count += route.getValue().size(); } BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), CHARSET)); // output amount of couples (routeId, stopId) out.write(String.valueOf(count)); out.newLine(); for (final Entry<String, Set<String>> route : routesToStops.entrySet()) { final String routeId = route.getKey(); for (final String stopId : route.getValue()) { out.write(routeId); out.write(';'); out.write(stopId); out.write(';'); out.newLine(); } } } catch (final FileNotFoundException e) { LOGGER.error("output file not found", e); } catch (final IOException e) { LOGGER.error("can't write to output file", e); } finally { IOUtils.closeQuietly(out); } }
From source file:net.sf.sessionAnalysis.SessionVisitorArrivalAndCompletionRate.java
public void writeSessionsOverTime(final String outputDir) throws IOException { FileWriter fw = new FileWriter(outputDir + "/" + this.getClass().getSimpleName() + "-sessionsOverTime.csv"); BufferedWriter writer = new BufferedWriter(fw); writer.write("timestamp;numSessions"); writer.newLine(); for (Entry<Long, Integer> event : this.numConcurrentSessionsOverTime.entrySet()) { writer.write(event.getKey() + ";" + event.getValue()); writer.newLine();/* w w w .j ava 2 s.c om*/ } writer.close(); fw.close(); }
From source file:com.stimulus.archiva.domain.Settings.java
public void store(String intro, OutputStream out, String charset) throws IOException { BufferedWriter output = new BufferedWriter(new OutputStreamWriter(out, charset)); output.append(intro);// ww w .j a v a2 s. co m for (Map.Entry<String, String> property : entrySet()) { output.append(property.getKey()); output.append(keyValueSeparator); output.append(property.getValue()); output.newLine(); } output.close(); }
From source file:edu.illinois.cs.cogcomp.core.datastructures.Lexicon.java
private void writeInt(BufferedWriter writer, int integer) throws IOException { writer.write(integer + ""); writer.newLine(); }
From source file:com.verigreen.collector.systemtest.SystemTestBase.java
/** * @param destinationFolderForNewFile//from w w w.ja va 2s .c o m * @param newFileName * @throws IOException */ protected void appendToFile(String pathToFile, String content) throws IOException { BufferedWriter outputCommiter3 = new BufferedWriter(new FileWriter(pathToFile, true)); outputCommiter3.newLine(); outputCommiter3.append(content); outputCommiter3.close(); }
From source file:br.bireme.accounts.Authentication.java
public JSONObject getUser(final String user, final String password) throws IOException, ParseException { if (user == null) { throw new NullPointerException("user"); }/*www .j av a2s . c o m*/ if (password == null) { throw new NullPointerException("password"); } final JSONObject parameters = new JSONObject(); parameters.put("username", user); parameters.put("password", password); parameters.put("service", SERVICE_NAME); parameters.put("format", "json"); //final URL url = new URL("http", host, port, DEFAULT_PATH); final URL url = new URL("http://" + host + DEFAULT_PATH); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoInput(true); connection.setDoOutput(true); connection.connect(); final StringBuilder builder = new StringBuilder(); final BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); //final String message = parameters.toJSONString(); //System.out.println(message); writer.write(parameters.toJSONString()); writer.newLine(); writer.close(); final int respCode = connection.getResponseCode(); final boolean respCodeOk = (respCode == 200); final BufferedReader reader; if (respCodeOk) { reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); } else { reader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); } while (true) { final String line = reader.readLine(); if (line == null) { break; } builder.append(line); builder.append("\n"); } reader.close(); if (!respCodeOk && (respCode != 401)) { throw new IOException(builder.toString()); } return (JSONObject) new JSONParser().parse(builder.toString()); }
From source file:org.web4thejob.print.CsvPrinter.java
@Override public File print(String title, List<RenderScheme> renderSchemes, Query query, List<Entity> entities) { Assert.notNull(renderSchemes);/*from ww w. j a va 2 s . c o m*/ int i = 0; File file; try { String crlf = System.getProperty("line.separator"); file = createTempFile(); BufferedWriter writer = createFileStream(file); writer.write(title + crlf); writer.newLine(); CSVWriter csv = new CSVWriter(writer); for (Entity entity : entities) { if (entity == null) { Assert.notNull(query); entity = ContextUtil.getDRS().findUniqueByQuery(query); } if (query != null && query.hasMasterCriterion()) { writer.write(describeMasterCriteria(query)); writer.newLine(); } if (query != null) { writer.write(describeCriteria(query)); writer.newLine(); } writeLine(csv, ContextUtil.getBean(ConversionService.class), entity, renderSchemes.get(i)); writer.newLine(); writer.newLine(); i++; } //timestamp List<String> line = new ArrayList<String>(); line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString()); MessageFormat df = new MessageFormat(""); df.setLocale(CoreUtil.getUserLocale()); df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}"); line.add(df.format(new Object[] { new Date() })); csv.writeNext(line.toArray(new String[line.size()])); writer.newLine(); writer.write("powered by web4thejob.org"); writer.close(); } catch (IOException e) { throw new RuntimeException(e); } return file; }