Example usage for com.google.common.io Files append

List of usage examples for com.google.common.io Files append

Introduction

In this page you can find the example usage for com.google.common.io Files append.

Prototype

public static void append(CharSequence from, File to, Charset charset) throws IOException 

Source Link

Usage

From source file:com.atoito.please.core.actions.AppendAction.java

protected void internalExecute() {
    try {// www  .  j a  v  a2s . c  o m
        Files.append(content, file, charset);
    } catch (IOException e) {
        throw new PleaseException("error appending content to " + file, e);
    }
}

From source file:com.android.build.gradle.internal.tasks.MergeFileTask.java

@TaskAction
public void mergeFiles() throws IOException {

    Set<File> files = getInputFiles();
    File output = getOutputFile();

    if (files.size() == 1) {
        Files.copy(files.iterator().next(), output);
        return;//from  ww  w.  java2 s . c o  m
    }

    // first delete the current file
    output.delete();

    // no input? done.
    if (files.isEmpty()) {
        return;
    }

    // otherwise put the all the files together
    for (File file : files) {
        String content = Files.toString(file, Charsets.UTF_8);
        Files.append(content, output, Charsets.UTF_8);
        Files.append("\n", output, Charsets.UTF_8);
    }
}

From source file:eus.ixa.ixa.pipe.tok.TokenizerEvaluator.java

private List<List<String>> referenceTokens(final List<Token> referenceList) {

    final List<List<String>> references = new ArrayList<List<String>>();
    for (int i = 0; i < referenceList.size(); i++) {
        final List<String> reference = Arrays
                .asList(new String[] { Integer.toString(i), referenceList.get(i).getTokenValue() });
        references.add(reference);/*  w w w .  j  a  v a 2s  .  c om*/

        if (DEBUG) {
            final StringBuilder sb = new StringBuilder();
            sb.append(referenceList.get(i).getTokenValue()).append(" ").append(reference).append("\n");
            try {
                Files.append(sb.toString(), new File("reference-tokens.log"), Charsets.UTF_8);
            } catch (final IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return references;
}

From source file:org.apache.brooklyn.test.performance.FilePersister.java

@Override
public void persist(Date date, PerformanceTestDescriptor options, PerformanceTestResult result) {
    try {//from  www . ja  v a  2  s . com
        String dateStr = new SimpleDateFormat(Time.DATE_FORMAT_PREFERRED).format(date);

        dir.mkdirs();

        File file = new File(dir, "auto-test-results.txt");
        file.createNewFile();
        Files.append("date=" + dateStr + "; test=" + options + "; result=" + result + "\n", file,
                Charsets.UTF_8);

        File summaryFile = new File(dir, "auto-test-summary.txt");
        summaryFile.createNewFile();
        Files.append(dateStr + "\t" + options.summary + "\t"
                + roundToSignificantFigures(result.ratePerSecond, 6) + "\t" + result.duration
                + (result.cpuTotalFraction != null
                        ? "\t" + "cpu=" + roundToSignificantFigures(result.cpuTotalFraction, 3)
                        : "")
                + "\n", summaryFile, Charsets.UTF_8);

    } catch (IOException e) {
        LOG.warn("Failed to persist performance results to " + dir + " (continuing)", e);
    }
}

From source file:org.btrplace.safeplace.testing.reporting.StoredReport.java

private void save(TestCaseResult res) {
    try {/*from  w ww. ja  v  a2 s .com*/
        java.nio.file.Files.deleteIfExists(file);
        Files.append("--------------------------------------------------------\n" + res.toString(),
                file.toFile(), Charset.defaultCharset());
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:com.android.build.gradle.integration.common.fixture.app.JavaGradleModule.java

@Override
public void write(@NonNull File projectDir, @Nullable String buildScriptContent) throws IOException {
    File sources = new File(projectDir, "src/main");
    sources.mkdirs();/*from   w  w  w  . j  a v  a2  s .  co m*/

    File resources = new File(projectDir, "src/resources");
    resources.mkdirs();

    if (buildScriptContent == null || buildScriptContent.isEmpty())
        buildScriptContent = getBuildGradleContent();

    Files.append(buildScriptContent, new File(projectDir, "build.gradle"), Charset.defaultCharset());
}

From source file:com.huawei.streaming.cql.executor.mergeuserdefinds.AppendRule.java

/**
 * {@inheritDoc}//from   w  w w.  ja va  2  s.c  o m
 */
@Override
public void execute(File srcFile, File distFile, String jarName) throws IOException {
    //???
    Files.append(IOUtils.LINE_SEPARATOR, distFile, CHARSET);
    Files.append(IOUtils.LINE_SEPARATOR, distFile, CHARSET);
    Files.append(String.format(COMMENT, jarName), distFile, CHARSET);
    Files.append(IOUtils.LINE_SEPARATOR, distFile, CHARSET);
    String line = FileUtils.readFileToString(srcFile, CHARSET);
    Files.append(line, distFile, CHARSET);
}

From source file:com.github.christofluyten.experiment.ResultWriter.java

static void appendTimeLogSummary(SimulationResult sr, File target) {
    if (sr.getResultObject() instanceof NycExperiment.ExperimentInfo) {
        final NycExperiment.ExperimentInfo info = (NycExperiment.ExperimentInfo) sr.getResultObject();

        final int tickInfoListSize = info.getTickInfoList().size();
        long sumIatNs = 0;
        for (final RealtimeTickInfo md : info.getTickInfoList()) {
            sumIatNs += md.getInterArrivalTime();
        }//www. j  ava2 s . c o  m

        try {
            Files.append(Joiner.on(',').join(sr.getSimArgs().getScenario().getProblemClass().getId(),
                    sr.getSimArgs().getScenario().getProblemInstanceId(),
                    sr.getSimArgs().getMasConfig().getName(), sr.getSimArgs().getRandomSeed(),
                    sr.getSimArgs().getRepetition(), tickInfoListSize,
                    tickInfoListSize == 0 ? 0 : sumIatNs / tickInfoListSize, info.getRtCount(),
                    info.getStCount() + "\n"), target, Charsets.UTF_8);
        } catch (final IOException e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:org.freeeed.services.Util.java

public static void appendToTextFile(String fileName, String content) throws IOException {
    Files.append(content, new File(fileName), Charset.defaultCharset());
}

From source file:org.sonatype.sisu.filetasks.task.internal.CreateFileTaskImpl.java

@Override
public void run() {
    checkNotNull(fileToCreate);//from   ww  w.  j av a 2s  .  c o m
    try {
        Files.createParentDirs(fileToCreate);
        fileToCreate.createNewFile();
        if (content != null) {
            Files.append(content, fileToCreate,
                    encoding == null ? Charset.defaultCharset() : Charset.forName(encoding));
        }
    } catch (IOException ex) {
        throw new RuntimeException("Could not create file", ex);
    }
}