List of usage examples for com.google.common.io Files append
public static void append(CharSequence from, File to, Charset charset) throws IOException
From source file:com.github.rinde.jaamas17.ResultWriter.java
void createCSVWithHeader(File f) { try {//ww w . j a v a 2 s .c om Files.createParentDirs(f); Files.append(Joiner.on(",").appendTo(new StringBuilder(), getFields()).append(System.lineSeparator()), f, Charsets.UTF_8); } catch (final IOException e1) { throw new IllegalStateException(e1); } }
From source file:de.tum.in.activity.log.ActivityLogService.java
/** * {@inheritDoc}//w ww . ja v a2 s. c om */ @Override public void saveLog(final String log) { LOGGER.debug("Saving log to the Activity Logs Database..."); try { Files.append(LocalDateTime.now() + " " + log + System.lineSeparator(), new File(LOCATION_TUM_LOG), Charsets.UTF_8); } catch (final IOException e) { LOGGER.error(Throwables.getStackTraceAsString(e)); } LOGGER.debug("Saving log to the Activity Logs Database...Done"); }
From source file:org.yomiassist.YomiassistProcessor.java
private void writeOutputFile(final Options options, String title, String author, List<Ruby> allRuby) throws IOException { options.outputFile.delete();/* w ww .j a va 2 s. c om*/ options.outputFile.createNewFile(); String headerContents = new String(Files.toByteArray(new File("templates/header.txt"))); headerContents = headerContents.replaceAll("%title%", title); headerContents = headerContents.replaceAll("%author%", author); Files.append(headerContents, options.outputFile, Charsets.UTF_8); XMLOutputter xmlOutputter = new XMLOutputter(); for (Ruby r : allRuby) { Files.append(xmlOutputter.outputString(r.toNode()) + '\n', options.outputFile, Charsets.UTF_8); } Files.append(new String(Files.toByteArray(new File("templates/footer.txt"))), options.outputFile, Charsets.UTF_8); }
From source file:com.swissbit.activity.log.ActivityLogService.java
/** * {@inheritDoc}/* w w w .jav a 2s.co m*/ */ @Override public void saveLog(final String log) { LOGGER.debug("Saving log to the Activity Logs Database..."); try { Files.append(LocalDateTime.now() + " " + log + System.lineSeparator(), new File(LOCATION_SWISSBIT_LOG), Charsets.UTF_8); } catch (final IOException e) { LOGGER.error(Throwables.getStackTraceAsString(e)); } LOGGER.debug("Saving log to the Activity Logs Database...Done"); }
From source file:com.hyperiongray.rcmp.ReportExtractor.java
private void createOutputFiles() throws IOException { new File(getOutputFile1()).delete(); Files.append(flatten(converToColumnNames(OutputColumns.TYPE_1), separator), new File(getOutputFile1()), Charset.defaultCharset()); new File(getOutputFile2()).delete(); Files.append(flatten(converToColumnNames(OutputColumns.TYPE_2), separator), new File(getOutputFile2()), Charset.defaultCharset()); logger.info("Will output into two files: {} and {}", getOutputFile1(), getOutputFile2()); }
From source file:org.locationtech.geogig.storage.fs.FileConflictsDatabase.java
/** * Adds a conflict to the database./* w ww .j a v a 2 s. c om*/ * * @param namespace the namespace of the conflict * @param conflict the conflict to add */ @Override public void addConflict(@Nullable String namespace, Conflict conflict) { final Object monitor = resolveConflictsMonitor(namespace); checkState(monitor != null, "Either not inside a repository directory or the staging area is closed"); synchronized (monitor) { Optional<File> fileOp = findOrCreateConflictsFile(namespace); checkState(fileOp.isPresent()); try { final File file = fileOp.get(); Files.append(conflict.toString() + "\n", file, Charsets.UTF_8); } catch (IOException e) { throw Throwables.propagate(e); } } }
From source file:com.github.rinde.jaamas17.ResultWriter.java
static void createTimeLogSummaryHeader(File target) { try {// w w w.ja v a 2s . co m Files.append( Joiner.on(',').join("problem-class", "instance", "config", "random-seed", "repetition", "rt-tick-infos", "avg-interarrival-time", "rt-count", "st-count\n"), target, Charsets.UTF_8); } catch (final IOException e) { throw new IllegalStateException(e); } }
From source file:com.github.rinde.gpem17.evo.StatsLogger.java
static void appendResults(Iterable<SimulationResult> results, File dest, String generationId) { StringBuilder sb = new StringBuilder(); for (SimulationResult sr : results) { SimResult ro = (SimResult) sr.getResultObject(); StatisticsDTO stats = ro.getStats(); final String pc = sr.getSimArgs().getScenario().getProblemClass().getId(); final String id = sr.getSimArgs().getScenario().getProblemInstanceId(); final String scenarioName = DASH_JOINER.join(pc, id); boolean isValid = GPEM17.OBJ_FUNC.isValidResult(stats); double cost = GPEM17.OBJ_FUNC.computeCost(stats); final ImmutableMap.Builder<Enum<?>, Object> map = ImmutableMap.<Enum<?>, Object>builder() .put(CsvFields.GENERATION, generationId).put(CsvFields.SCENARIO_ID, scenarioName) .put(CsvFields.RANDOM_SEED, sr.getSimArgs().getRandomSeed()).put(CsvFields.COST, cost) .put(CsvFields.TRAVEL_TIME, GPEM17.OBJ_FUNC.travelTime(stats)) .put(CsvFields.TARDINESS, GPEM17.OBJ_FUNC.tardiness(stats)) .put(CsvFields.OVER_TIME, GPEM17.OBJ_FUNC.overTime(stats)).put(CsvFields.IS_VALID, isValid) .put(CsvFields.NUM_ORDERS, stats.totalParcels).put(CsvFields.NUM_VEHICLES, stats.totalVehicles) .put(CsvFields.COST_PER_PARCEL, isValid ? cost / (double) stats.totalParcels : "invalid"); if (ro.getAuctionStats().isPresent()) { final AuctionStats aStats = ro.getAuctionStats().get(); map.put(CsvFields.NUM_REAUCTIONS, aStats.getNumReauctions()) .put(CsvFields.NUM_UNSUC_REAUCTIONS, aStats.getNumUnsuccesfulReauctions()) .put(CsvFields.NUM_FAILED_REAUCTIONS, aStats.getNumFailedReauctions()); } else {/* w ww .j a v a2 s .co m*/ map.put(CsvFields.NUM_REAUCTIONS, -1).put(CsvFields.NUM_UNSUC_REAUCTIONS, -1) .put(CsvFields.NUM_FAILED_REAUCTIONS, -1); } appendValuesTo(sb, map.build(), CsvFields.values()).append(System.lineSeparator()); } try { Files.append(sb.toString(), dest, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.spongepowered.asm.mixin.transformer.MixinTransformerModuleInterfaceChecker.java
private void appendToCSVReport(String className, Method method, String iface) { try {//from w w w . j a v a2 s .c o m Files.append(String.format("%s,%s,%s,%s\n", className, method.getName(), method.getDesc(), iface), this.csv, Charsets.ISO_8859_1); } catch (IOException ex) { // Not the end of the world } }
From source file:me.ryanhamshire.griefprevention.logging.CustomLogger.java
void writeEntries() { try {/* w w w.j av a 2 s.c o m*/ // if nothing to write, stop here if (this.queuedEntries.length() == 0) { return; } // determine filename based on date String filename = this.filenameFormat.format(new Date()) + ".log"; String filepath = this.logFolderPath + File.separator + filename; File logFile = new File(filepath); // dump content Files.append(this.queuedEntries.toString(), logFile, Charset.forName("UTF-8")); // in case of a failure to write the above due to exception, // the unwritten entries will remain the buffer for the next write // to retry this.queuedEntries.setLength(0); } catch (Exception e) { e.printStackTrace(); } }