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:org.opendaylight.yangtools.checkstyle.LogMessageExtractorCheck.java

protected void updateMessagesReportFile(LogMessageOccurence log) {
    try {/*from   w  w  w .j av a2  s  .  c om*/
        final File file = getLogMessagesReportFile();
        file.getParentFile().mkdirs();
        if (file.exists()) {
            Files.append(log.toString() + "\n", file, StandardCharsets.UTF_8);
        } else {
            Files.write(log.toString() + "\n", file, StandardCharsets.UTF_8);
        }
    } catch (IOException e) {
        LOG.error("Failed to append to file: {}", logMessagesReportFile.getPath(), e);
    }
}

From source file:com.shmsoft.dmass.main.WindowsReduce.java

@Override
protected void setup(Reducer.Context context) throws IOException, InterruptedException {
    Project project = Project.getProject();
    metadataOutputFileName = project.getResultsDir() + "/metadata" + ParameterProcessing.METADATA_FILE_EXT;

    // TODO what is this doing in Windows environment?
    if (project.isEnvHadoop()) {
        String metadataFileContents = context.getConfiguration().get(ParameterProcessing.METADATA_FILE);
        Files.write(metadataFileContents.getBytes(), new File(ColumnMetadata.metadataNamesFile));
    }//from  ww w .j  a  v a2 s  .  com
    columnMetadata = new ColumnMetadata();
    String fileSeparatorStr = project.getFieldSeparator();
    char fieldSeparatorChar = Delim.getDelim(fileSeparatorStr);
    columnMetadata.setFieldSeparator(String.valueOf(fieldSeparatorChar));
    columnMetadata.setAllMetadata(project.getMetadataCollect());
    // write standard metadata fields
    new File(project.getResultsDir()).mkdirs();
    Files.append(columnMetadata.delimiterSeparatedHeaders() + "\n", new File(metadataOutputFileName),
            Charset.defaultCharset());
    zipFileWriter.setup();
    zipFileWriter.openZipForWriting();
}

From source file:org.apache.s4.example.twitter.TopNTopicPE.java

public void onTime() {
    TreeSet<TopNEntry> sortedTopics = Sets.newTreeSet();
    for (Map.Entry<String, Integer> topicCount : countedTopics.entrySet()) {
        sortedTopics.add(new TopNEntry(topicCount.getKey(), topicCount.getValue()));
    }//from   w w  w .  j  a v  a2 s . c o m

    File f = new File("TopNTopics.txt");

    StringBuilder sb = new StringBuilder();
    int i = 0;
    Iterator<TopNEntry> iterator = sortedTopics.iterator();
    sb.append("----\n" + new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss").format(new Date()) + "\n");

    while (iterator.hasNext() && i < 10) {
        TopNEntry entry = iterator.next();
        sb.append("topic [" + entry.topic + "] count [" + entry.count + "]\n");
        i++;
    }
    sb.append("\n");
    try {
        Files.append(sb.toString(), f, Charsets.UTF_8);
        logger.info("Wrote top 10 topics to file [{}] ", f.getAbsolutePath());
    } catch (IOException e) {
        logger.error("Cannot write top 10 topics to file [{}]", f.getAbsolutePath(), e);
    }
}

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

private List<List<String>> predictionTokens(final List<Token> predictionList) {

    final List<List<String>> predictions = new ArrayList<List<String>>();
    for (int j = 0; j < predictionList.size(); j++) {
        final List<String> prediction = Arrays
                .asList(new String[] { Integer.toString(j), predictionList.get(j).getTokenValue() });
        predictions.add(prediction);//from w w w  .jav a2s.  co m

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

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

private void setVarInUnixLike(String name, String value) {
    // Files.append(from, bashrc, charset)
    String userHome = System.getProperty("user.home");
    String bashrcPath = userHome + "/.bashrc";
    M.info("appending line to .bashrc");
    File bashrc = new File(bashrcPath);
    String varDeclaration = String.format("%nexport %s=\"%s\"%n", name, value);
    M.info(varDeclaration);/* ww  w  .j a  v  a 2  s . co m*/
    try {
        Files.append(varDeclaration, bashrc, Charsets.UTF_8);
    } catch (IOException e) {
        throw new PleaseException("error appending to .bashrc", e);
    }
}

From source file:com.shmsoft.dmass.main.WindowsReduce.java

@Override
protected void cleanup(Reducer.Context context) throws IOException, InterruptedException {

    if (!Project.getProject().isMetadataCollectStandard()) {
        // write summary headers with all metadata
        Files.append("\n" + columnMetadata.delimiterSeparatedHeaders(), new File(metadataOutputFileName),
                Charset.defaultCharset());
    }//from  ww  w.java  2  s .c om

    zipFileWriter.closeZip();
    Stats.getInstance().setJobFinished();
    String outputSuccess = Project.getProject().getResultsDir() + "/_SUCCESS";
    Files.write("", new File(outputSuccess), Charset.defaultCharset());
}

From source file:brooklyn.entity.rebind.persister.FileBasedStoreObjectAccessor.java

@Override
public void append(String val) {
    try {//from ww w  .  j  av  a 2 s. com
        if (val == null)
            val = "";
        FileUtil.setFilePermissionsTo600(file);
        Files.append(val, file, Charsets.UTF_8);

    } catch (IOException e) {
        throw Exceptions.propagate(e);
    }
}

From source file:com.cinchapi.concourse.util.FileOps.java

/**
 * Write the String {@code content} to the end of the {@code file},
 * preserving anything that was previously there.
 * /*from   w  w w  .j a  v a  2s  .co  m*/
 * @param content the data to write
 * @param file the path to the file
 */
public static void append(String content, String file) {
    try {
        Files.append(content, new File(file), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:spv.sherpa.custom.CustomModelsManager.java

public void addModel(CustomModel model, String type) throws IOException {
    File file = new File(model.getUrl().getFile());
    File destination = null;/* w  w  w  .  j  a v  a2s . c o  m*/
    if (type.equals("Template Library"))
        destination = templatesDir;
    if (type.equals("Python Function"))
        destination = functionsDir;
    if (type.equals("Table"))
        destination = tablesDir;

    String name;

    if (model.getName() == null)
        model.setName("");

    name = model.getName().isEmpty()
            ? model.getUrl().getFile().substring(model.getUrl().getFile().lastIndexOf(File.separator) + 1)
            : model.getName();

    File target = new File(destination.getAbsolutePath() + File.separator + name);

    if (file.equals(target)) {
        File temp = new File(file.getAbsolutePath() + ".temp");
        Files.copy(file, temp);
        Files.copy(temp, target);
        temp.delete();
    } else {
        Files.copy(file, target);
    }

    File specs = new File(target.getAbsolutePath() + ".specs");

    String functionName = destination.equals(functionsDir) ? model.getFunctionName() : "None";

    Files.write(functionName + "\n", specs, Charsets.UTF_8);
    Files.append(model.getParnames() + "\n", specs, Charsets.UTF_8);
    Files.append(model.getParvals() + "\n", specs, Charsets.UTF_8);
    Files.append(model.getParmins() + "\n", specs, Charsets.UTF_8);
    Files.append(model.getParmaxs() + "\n", specs, Charsets.UTF_8);
    Files.append(model.getParfrozen() + "\n", specs, Charsets.UTF_8);
}

From source file:cfa.vo.iris.logger.IrisLogger.java

@Override
public void process(Object source, LogEntry payload) {
    try {/*from w ww . j  a va 2s  .  com*/
        Files.append(payload.getFormatted() + "\n", logFile, Charsets.UTF_8);
    } catch (IOException ex) {
        NarrowOptionPane.showMessageDialog(ws.getRootFrame(),
                "Cannot write to file: " + logFile.getAbsolutePath(), "Logger", NarrowOptionPane.ERROR_MESSAGE);
    }
}