Example usage for java.io BufferedWriter BufferedWriter

List of usage examples for java.io BufferedWriter BufferedWriter

Introduction

In this page you can find the example usage for java.io BufferedWriter BufferedWriter.

Prototype

public BufferedWriter(Writer out) 

Source Link

Document

Creates a buffered character-output stream that uses a default-sized output buffer.

Usage

From source file:be.ac.ua.comp.scarletnebula.core.KeyManager.java

/**
 * Takes a keyname, an actual key and a provider name (for which this key
 * works) and then stores the key on disk.
 * /*  www.  j ava 2 s .  c  o  m*/
 * @param providerName
 * @param keyname
 * @param keystring
 */
static void addKey(final String providerName, final String keyname, final String keystring) {
    if (assureDirectory(providerName) == null) {
        return;
    }

    // Now store the key to file
    BufferedWriter out;
    try {
        out = new BufferedWriter(new FileWriter(getKeyFilename(providerName, keyname)));
        out.write(keystring);
        out.close();
    } catch (final IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.kloudtek.buildmagic.tools.createinstaller.deb.CopyrightList.java

public void write(DataBuffer copyright, CreateDebTask task) throws IOException {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(copyright));
    writer.write("Format: http://dep.debian.net/deps/dep5\n");
    if (task.getUpstreamName() != null) {
        writer.write("Upstream-Name: " + task.getUpstreamName() + " \n");
    }//from   ww  w  . j  a v  a 2 s  . c  o  m
    if (task.getUpstreamUrl() != null) {
        writer.write("Source: " + task.getUpstreamUrl() + " \n");
    }
    writer.write("\n");
    for (Copyright cr : this) {
        writer.write("Files: ");
        if (cr.getFiles() != null) {
            writer.write("*");
        } else {
            writer.write(cr.getFiles());
        }
        boolean first = true;
        for (CopyrightAuthor author : cr.getAuthors()) {
            if (first) {
                writer.write("\nCopyright: ");
                first = false;
            } else {
                writer.write("\n           ");
            }
            String year = author.getYear() != null ? author.getYear() : getCurrentYear();
            writer.write(year);
            writer.write(" ");
            String name = author.getName() != null ? author.getName() : task.getMaintName();
            writer.write(name);
            String email = author.getEmail() != null ? author.getEmail() : task.getMaintEmail();
            writer.write(" <");
            writer.write(email);
            writer.write(">\nLicense: ");
            writer.write(cr.getLicense());
            writer.write("\n ");
            String licTxt = FileUtils.readFileToString(cr.getLicenseFile());
            licTxt = licTxt.replace("\n\n", "\n.\n").replace("\n", "\n ");
            writer.write(licTxt);
            writer.write("\n\n");
        }
    }
    writer.close();
}

From source file:jsonconverter.createandwrite.JSONFileWriter.java

public void createFile(String name, String JSONFolderPath) {
    try {/*  w w  w.j av  a 2  s.  com*/
        File file = new File(JSONFolderPath, name + ".txt");
        file.createNewFile();
        FileWriter fw = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(obj.toString());
        bw.flush();
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.codemage.sql.util.SonarQubeManager.java

public void createJavaFile(String JavaCode) {
    BufferedWriter bw = null;/*from ww  w .  j a  v  a 2  s  .  com*/

    try {
        // APPEND MODE SET HERE
        bw = new BufferedWriter(new FileWriter(
                "E:\\Smile24\\Projects\\0005 - CAL\\sampleAnalyseCode\\src\\main\\java\\checkbook.java",
                false));
        bw.write(JavaCode);
        bw.newLine();
        bw.flush();
    } catch (IOException ioe) {
    } finally { // always close the file
        if (bw != null) {
            try {
                bw.close();
            } catch (IOException ioe2) {
                // just ignore it
            }
        }
    } // end try/catch/finally
}

From source file:fm.last.commons.io.LastFileUtils.java

/**
 * Appends the passed string to the passed file.
 * /*from   w  w  w .  ja  va 2 s.com*/
 * @param file File to append string to (will be created if it does not exist).
 * @param string String to append.
 * @throws IOException If an error occurs appending the string to the file.
 */
public static void appendStringToFile(File file, String string) throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
    writer.write(string);
    writer.close();
}

From source file:Main.java

/**
 * Writes the current app logcat to a file.
 *
 * @param filename The filename to save it as
 * @throws IOException/*from   w  ww. j av  a  2s .  com*/
 */
public static void writeLogcat(String filename) throws IOException {
    String[] args = { "logcat", "-v", "time", "-d" };

    Process process = Runtime.getRuntime().exec(args);
    InputStreamReader input = new InputStreamReader(process.getInputStream());
    OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(filename));
    BufferedReader br = new BufferedReader(input);
    BufferedWriter bw = new BufferedWriter(output);
    String line;

    while ((line = br.readLine()) != null) {
        bw.write(line);
        bw.newLine();
    }

    bw.close();
    output.close();
    br.close();
    input.close();
}

From source file:edu.asu.cse564.samples.crud.io.GradebookIO.java

public static void writeToGradebook(List<Gradebook> gradebookList, String filename) {
    //GradebookIO gbio = new GradebookIO();
    try {//w w w . j a  va 2s  .  c o  m
        //String path = gbio.getPath(filename);
        String path = filename;
        File file = new File(path);

        // if file doesnt exists, then create it
        if (!file.exists()) {
            LOG.info("Creating file as it does not exist");
            file.createNewFile();
            LOG.debug("Created file = {}", file.getAbsolutePath());
        }
        String jsonString = null;
        jsonString = Converter.convertFromObjectToJSON(gradebookList, gradebookList.getClass());
        LOG.info("File path = {}", file.getAbsolutePath());
        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        try (BufferedWriter bw = new BufferedWriter(fw)) {
            bw.write(jsonString);
        }
    } catch (Exception e) {
        e.printStackTrace();
        ;
    }
}

From source file:tomekkup.helenos.web.servlet.view.CsvView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.setHeader("Content-Disposition",
            "attachment; filename=\"" + (String) model.get("key") + "_" + (String) model.get("key") + ".csv\"");
    BufferedWriter writer = new BufferedWriter(response.getWriter());

    //myDbData = (Whatever) modelMap.get("modelKey");
    //some kind of loop {writer.write(myDbData csv row); writer.newLine(); }
    writer.flush();//from   w  ww.  j av  a 2  s  . c om
    writer.close();
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.TextsResumeToJson.java

private static void saveResults(JSONArray recomendations, String id) {
    Writer out;// w ww  .  j  a v a 2 s .  c  o  m
    try {
        out = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream("data_toVisualize/data_resume/resume_" + id + ".json"), "UTF-8"));

        try {
            out.write(recomendations.toJSONString());
            out.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:LVCoref.MMAX2.java

public static void exportMentions(Document d, String filename) {
    BufferedWriter writer = null;
    try {//from  w ww .  ja  va2 s  .  com
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));
    } catch (java.io.IOException ex) {
        ex.printStackTrace();
    }
    Utils.toWriter(writer,
            "<?xml version=\"1.0\" encoding=\"" + "UTF-8" + "\"?>\n"
                    + "<!DOCTYPE markables SYSTEM \"markables.dtd\">\n"
                    + "<markables xmlns=\"www.eml.org/NameSpaces/" + "coref" + "\">\n");
    for (Mention m : d.mentions) {
        String span = "";
        if (m.start == m.end)
            span = "word_" + (m.start + 1);
        else
            span = "word_" + (m.start + 1) + ".." + "word_" + (m.end + 1);
        String coref_class = "";
        if (d.corefClusters.get(m.corefClusterID).corefMentions.size() > 1)
            coref_class = "set_" + m.corefClusterID;
        else
            coref_class = "empty";
        String category = "other";
        if (m.category != null) {
            if (m.category.equals("ORG"))
                category = "organization";
            else if (m.category.equals("LOCATION"))
                category = "location";
            else if (m.category.equals("PERSON"))
                category = "person";
        }

        Utils.toWriter(writer,
                "<markable id=\"markable_" + (m.id + 1) + "\" span=\"" + span + "\" coref_class=\""
                        + coref_class + "\" category=\"" + category
                        + "\" mmax_level=\"coref\"  rule=\"none\"  type=\"none\"/>\n");
    }
    Utils.toWriter(writer, "</markables>");
    try {
        writer.flush();
        writer.close();
    } catch (IOException ex) {
        Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex);
    }
}