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:org.primefaces.extensions.optimizerplugin.optimizer.AbstractOptimizer.java
protected File aggregateFiles(ResourcesSetAdapter rsa, Charset cset, boolean delimeters) throws IOException { File outputFile = getOutputFile(rsa); if (rsa.getAggregation().getPrependedFile() != null) { // write / append to be prepended file into / to the output file prependFile(rsa.getAggregation().getPrependedFile(), outputFile, cset, rsa); }/*from w w w .java2 s.com*/ for (File file : rsa.getFiles()) { Reader in = getReader(rsa, file); StringWriter writer = new StringWriter(); IOUtil.copy(in, writer); if (delimeters && outputFile.length() > 0) { // append semicolon to the new file in order to avoid invalid JS code Files.append(";", outputFile, cset); } // write / append content into / to the new file Files.append(writer.toString(), outputFile, cset); IOUtil.close(in); } return outputFile; }
From source file:org.primefaces.extensions.optimizerplugin.AbstractOptimizer.java
protected File aggregateFiles(final ResourcesSetAdapter rsa, final Charset cset, final Log log) throws IOException { int filesCount = rsa.getFiles().size(); if (rsa.getAggregation().getPrependedFile() != null) { filesCount++;/*from www . jav a2s. com*/ } if (filesCount > 1) { log.info("Aggregation is running ..."); } File outputFile = getOutputFile(rsa); if (rsa.getAggregation().getPrependedFile() != null) { // write / append to be prepended file into / to the output file prependFile(rsa.getAggregation().getPrependedFile(), outputFile, cset, rsa.getEncoding()); } for (File file : rsa.getFiles()) { InputStreamReader in = new InputStreamReader(new FileInputStream(file), rsa.getEncoding()); StringWriter writer = new StringWriter(); IOUtil.copy(in, writer); // write / append compiled content into / to the new file Files.append(writer.toString(), outputFile, cset); IOUtil.close(in); } if (filesCount > 1) { log.info(filesCount + " files were successfully aggregated."); } return outputFile; }
From source file:com.facebook.buck.dalvik.DefaultZipOutputStreamHelper.java
@Override public void putEntry(FileLike fileLike) throws IOException { String name = fileLike.getRelativePath(); // Tracks unique entry names and avoids duplicates. This is, believe it or not, how // proguard seems to handle merging multiple -injars into a single -outjar. if (!containsEntry(fileLike)) { entryNames.add(name);/* w w w.ja v a 2s . com*/ outStream.putNextEntry(new ZipEntry(name)); try (InputStream in = fileLike.getInput()) { ByteStreams.copy(in, outStream); } // Make sure FileLike#getSize didn't lie (or we forgot to call canPutEntry). long entrySize = getSize(fileLike); Preconditions.checkState(!isEntryTooBig(entrySize), "Putting entry %s (%s) exceeded maximum size of %s", name, entrySize, zipSizeHardLimit); currentSize += entrySize; String report = String.format("%s %s\n", entrySize, name); Files.append(report, reportFile, Charsets.UTF_8); } }
From source file:com.github.christofluyten.experiment.LuytenResultWriter.java
@Override void appendSimResult(SimulationResult sr, File destFile) { final String pc = sr.getSimArgs().getScenario().getProblemClass().getId(); final String id = sr.getSimArgs().getScenario().getProblemInstanceId(); try {//from w ww . j a v a2 s . c om final String scenarioName = Joiner.on("-").join(pc, id); final List<String> propsStrings = Files .readLines(new File("files/datasets/" + scenarioName + ".properties"), Charsets.UTF_8); final Map<String, String> properties = Splitter.on("\n").withKeyValueSeparator(" = ") .split(Joiner.on("\n").join(propsStrings)); final ImmutableMap.Builder<Enum<?>, Object> map = ImmutableMap.<Enum<?>, Object>builder() .put(OutputFields.SCENARIO_ID, scenarioName) // .put(OutputFields.DYNAMISM, properties.get("dynamism_bin")) // .put(OutputFields.URGENCY, properties.get("urgency")) // .put(OutputFields.SCALE, properties.get("scale")) // .put(OutputFields.NUM_ORDERS, properties.get("AddParcelEvent")) // .put(OutputFields.NUM_VEHICLES, properties.get("AddVehicleEvent")) .put(OutputFields.RANDOM_SEED, sr.getSimArgs().getRandomSeed()) .put(OutputFields.REPETITION, sr.getSimArgs().getRepetition()); addSimOutputs(map, sr, objectiveFunction); final String line = MeasureGendreau.appendValuesTo(new StringBuilder(), map.build(), getFields()) .append(System.lineSeparator()).toString(); Files.append(line, destFile, Charsets.UTF_8); } catch (final IOException e) { throw new IllegalStateException(e); } }
From source file:org.apache.brooklyn.core.mgmt.persist.FileBasedStoreObjectAccessor.java
@Override public void append(String val) { try {//from w w w. java 2s .com if (val == null) val = ""; FileUtil.setFilePermissionsTo600(file); Files.append(val, file, Charsets.UTF_8); } catch (IOException e) { throw Exceptions.propagate("Problem appending to file " + file, e); } }
From source file:com.github.rinde.gpem17.eval.SimRuntimeLogger.java
void write() { lastWrite = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); String timestamp = ISODateTimeFormat.dateHourMinuteSecond().print(lastWrite); long sum = 0; double[] arr = new double[receivedResults.size()]; for (int i = 0; i < receivedResults.size(); i++) { SimResult info = (SimResult) receivedResults.get(i).getResultObject(); sum += info.getStats().computationTime; arr[i] = info.getStats().computationTime; }//from www . j av a 2 s . c om double mean = sum / receivedResults.size(); long sd = DoubleMath.roundToLong(new StandardDeviation().evaluate(arr, mean), RoundingMode.HALF_DOWN); long longMean = DoubleMath.roundToLong(mean, RoundingMode.HALF_DOWN); sb.append(timestamp).append(",").append(receivedSims).append("/").append(totalSims).append(", Received ") .append(receivedResults.size()).append(" results in last minute, avg comp time,") .append(PeriodFormat.getDefault().print(new Period(longMean))).append(", standard deviation,") .append(PeriodFormat.getDefault().print(new Period(sd))).append(System.lineSeparator()); try { Files.append(sb.toString(), progressFile, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException(e); } receivedResults.clear(); }
From source file:com.shmsoft.dmass.main.WindowsReduce.java
@Override public void reduce(MD5Hash key, Iterable<MapWritable> values, Context context) throws IOException, InterruptedException { isMaster = true;/*from w ww . ja v a 2 s . c o m*/ for (MapWritable value : values) { columnMetadata.reinit(); ++outputFileCount; processMap(value); Files.append(columnMetadata.delimiterSeparatedValues() + "\n", new File(metadataOutputFileName), Charset.defaultCharset()); isMaster = false; } }
From source file:com.google.dart.java2dart.engine.MainEngine.java
public static void main(String[] args) throws Exception { if (args.length != 2 && args.length != 3) { System.out.println("Usage: java2dart <target-src-folder> <target-test-folder> [src-package]"); System.exit(0);/* www . j a v a 2s . c om*/ } String targetFolder = args[0]; String targetTestFolder = args[1]; if (args.length == 3) { System.out.println("Overrriding default src package to: " + src_package); src_package = args[2]; } System.out.println("Generating files into " + targetFolder); new File(targetFolder).mkdirs(); // engineFolder = new File("../../../tools/plugins/com.google.dart.engine/src"); engineTestFolder = new File("../../../tools/plugins/com.google.dart.engine_test/src"); engineFolder2 = new File("src"); engineFolder = engineFolder.getCanonicalFile(); // configure Context context.addClasspathFile(new File("../../../../third_party/guava/r13/guava-13.0.1.jar")); context.addClasspathFile(new File("../../../../third_party/junit/v4_8_2/junit.jar")); context.addSourceFolder(engineFolder); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/utilities/ast")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/utilities/instrumentation")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/sdk")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/sdk")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/source")); context.addSourceFile(new File(engineFolder, "com/google/dart/engine/utilities/source/LineInfo.java")); context.addSourceFile(new File(engineFolder, "com/google/dart/engine/utilities/source/SourceRange.java")); context.addSourceFile(new File(engineFolder, "com/google/dart/engine/utilities/dart/ParameterKind.java")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/ast")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/ast/visitor")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/constant")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/element")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/error")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/html/ast")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/html/ast/visitor")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/html/parser")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/html/scanner")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/parser")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/resolver")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/scanner")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/type")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/builder")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/cache")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/constant")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/element")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/error")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/parser")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/resolver")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/scope")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/type")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/verifier")); context.addSourceFile( new File(engineFolder2, "com/google/dart/java2dart/util/ToFormattedSourceVisitor.java")); context.addSourceFile(new File(engineFolder, "com/google/dart/engine/AnalysisEngine.java")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/utilities/logging")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/context")); context.addSourceFiles(new File(engineFolder, "com/google/dart/engine/internal/context")); // Tests context.addSourceFile( new File(engineTestFolder, "com/google/dart/engine/utilities/io/FileUtilities2.java")); context.addSourceFile(new File(engineTestFolder, "com/google/dart/engine/EngineTestCase.java")); context.addSourceFile( new File(engineTestFolder, "com/google/dart/engine/error/GatheringErrorListener.java")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/scanner")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/parser")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/ast")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/element")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/internal/element")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/internal/type")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/resolver")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/internal/resolver")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/internal/scope")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/context")); context.addSourceFiles(new File(engineTestFolder, "com/google/dart/engine/internal/context")); // configure renames context.addRename("Lcom/google/dart/engine/ast/IndexExpression;.(Lcom/google/dart/engine/ast/Expression;" + "Lcom/google/dart/engine/scanner/Token;Lcom/google/dart/engine/ast/Expression;" + "Lcom/google/dart/engine/scanner/Token;)", "forTarget"); context.addRename("Lcom/google/dart/engine/ast/IndexExpression;.(Lcom/google/dart/engine/scanner/Token;" + "Lcom/google/dart/engine/scanner/Token;Lcom/google/dart/engine/ast/Expression;" + "Lcom/google/dart/engine/scanner/Token;)", "forCascade"); context.addRename( "Lcom/google/dart/engine/html/ast/XmlTagNode;.becomeParentOf<T:Lcom/google/dart/engine/html/ast/XmlNode;>(Ljava/util/List<TT;>;Ljava/util/List<TT;>;)", "becomeParentOfEmpty"); // translate into single CompilationUnit dartUnit = context.translate(); // run processors { List<SemanticProcessor> PROCESSORS = ImmutableList.of(new ConstructorSemanticProcessor(context), new ObjectSemanticProcessor(context), new CollectionSemanticProcessor(context), new IOSemanticProcessor(context), new PropertySemanticProcessor(context), new GuavaSemanticProcessor(context), new JUnitSemanticProcessor(context), new BeautifySemanticProcessor(context), new EngineSemanticProcessor(context)); for (SemanticProcessor processor : PROCESSORS) { processor.process(dartUnit); } } // run this again, because we may introduce conflicts when convert methods to getters/setters context.ensureUniqueClassMemberNames(dartUnit); context.ensureNoVariableNameReferenceFromInitializer(dartUnit); context.ensureMethodParameterDoesNotHide(dartUnit); // handle reflection EngineSemanticProcessor.rewriteReflectionFieldsWithDirect(context, dartUnit); // dump as several libraries Files.copy(new File("resources/java_core.dart"), new File(targetFolder + "/java_core.dart")); Files.copy(new File("resources/java_io.dart"), new File(targetFolder + "/java_io.dart")); Files.copy(new File("resources/java_junit.dart"), new File(targetFolder + "/java_junit.dart")); Files.copy(new File("resources/java_engine.dart"), new File(targetFolder + "/java_engine.dart")); Files.copy(new File("resources/java_engine_io.dart"), new File(targetFolder + "/java_engine_io.dart")); Files.copy(new File("resources/all_test.dart"), new File(targetTestFolder + "/all_test.dart")); { CompilationUnit library = buildInstrumentationLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/instrumentation.dart"), Charsets.UTF_8); } { CompilationUnit library = buildSourceLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/source.dart"), Charsets.UTF_8); } { CompilationUnit library = buildSourceIoLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/source_io.dart"), Charsets.UTF_8); } { CompilationUnit library = buildErrorLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/error.dart"), Charsets.UTF_8); } { CompilationUnit library = buildScannerLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/scanner.dart"), Charsets.UTF_8); } { CompilationUnit library = buildHtmlLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/html.dart"), Charsets.UTF_8); } { CompilationUnit library = buildUtilitiesDartLibrary(); File astFile = new File(targetFolder + "/utilities_dart.dart"); Files.write(getFormattedSource(library), astFile, Charsets.UTF_8); } { CompilationUnit library = buildAstLibrary(); File astFile = new File(targetFolder + "/ast.dart"); Files.write(getFormattedSource(library), astFile, Charsets.UTF_8); Files.append(Files.toString(new File("resources/ast_include.dart"), Charsets.UTF_8), astFile, Charsets.UTF_8); } { CompilationUnit library = buildParserLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/parser.dart"), Charsets.UTF_8); } { CompilationUnit library = buildSdkLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/sdk.dart"), Charsets.UTF_8); } { CompilationUnit library = buildSdkIoLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/sdk_io.dart"), Charsets.UTF_8); } { CompilationUnit library = buildConstantLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/constant.dart"), Charsets.UTF_8); } { CompilationUnit library = buildElementLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/element.dart"), Charsets.UTF_8); } { CompilationUnit library = buildResolverLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/resolver.dart"), Charsets.UTF_8); } { CompilationUnit library = buildEngineLibrary(); Files.write(getFormattedSource(library), new File(targetFolder + "/engine.dart"), Charsets.UTF_8); } // Tests { CompilationUnit library = buildTestSupportLibrary(); File testSupportFile = new File(targetTestFolder + "/test_support.dart"); Files.write(getFormattedSource(library), testSupportFile, Charsets.UTF_8); Files.append(Files.toString(new File("resources/test_support_include.dart"), Charsets.UTF_8), testSupportFile, Charsets.UTF_8); } { CompilationUnit library = buildScannerTestLibrary(); Files.write(getFormattedSource(library), new File(targetTestFolder + "/scanner_test.dart"), Charsets.UTF_8); } { CompilationUnit library = buildParserTestLibrary(); // replace reflection methods StringWriter methodWriter = new StringWriter(); EngineSemanticProcessor.replaceReflectionMethods(context, new PrintWriter(methodWriter), dartUnit); // write to file File libraryFile = new File(targetTestFolder + "/parser_test.dart"); Files.write(getFormattedSource(library), libraryFile, Charsets.UTF_8); Files.append(methodWriter.toString(), libraryFile, Charsets.UTF_8); } { CompilationUnit library = buildAstTestLibrary(); File astFile = new File(targetTestFolder + "/ast_test.dart"); Files.write(getFormattedSource(library), astFile, Charsets.UTF_8); } { CompilationUnit library = buildElementTestLibrary(); Files.write(getFormattedSource(library), new File(targetTestFolder + "/element_test.dart"), Charsets.UTF_8); } { CompilationUnit library = buildResolverTestLibrary(); Files.write(getFormattedSource(library), new File(targetTestFolder + "/resolver_test.dart"), Charsets.UTF_8); } System.out.println("Translation complete"); }
From source file:com.axelor.data.csv.CSVLogger.java
/** * Log the row into a specific file./*w w w. j a v a2 s. co m*/ * @param values * @param csvBinder * @param csvInput */ public void log(String[] values) { if (this.errorDir == null || this.currentFile == null || this.csvInput == null) { return; } this.exportInput(); try { if (!this.currentFile.exists()) { Files.createParentDirs(this.currentFile); Files.append(Joiner.on(this.csvInput.getSeparator()).join(this.transformLine(this.header)), this.currentFile, Charsets.UTF_8); this.filesName.add(this.currentFile.getName()); } Files.append("\n" + Joiner.on(this.csvInput.getSeparator()).join(this.transformLine(values)), this.currentFile, Charsets.UTF_8); } catch (IOException e) { } }
From source file:brooklyn.entity.rebind.persister.MementoFileWriterSync.java
public void append(T val) { try {//from w ww . j a va 2 s.c om lock.writeLock().lockInterruptibly(); } catch (InterruptedException e) { throw Exceptions.propagate(e); } try { Stopwatch stopwatch = Stopwatch.createStarted(); // Write to the temp file, then atomically move it to the permanent file location Files.append(serializer.toString(val), file, Charsets.UTF_8); modCount.incrementAndGet(); if (LOG.isTraceEnabled()) LOG.trace("Wrote {}, took {}; modified file {} times", new Object[] { file, Time.makeTimeStringRounded(stopwatch), modCount }); } catch (IOException e) { throw Exceptions.propagate(e); } finally { lock.writeLock().unlock(); } }