Example usage for java.io FileWriter append

List of usage examples for java.io FileWriter append

Introduction

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

Prototype

@Override
    public Writer append(CharSequence csq) throws IOException 

Source Link

Usage

From source file:gov.nih.nci.caintegrator.application.query.GenomicDataFileWriter.java

private static void writeAsCsvRow(FileWriter writer, List<String> csvRowStrings) throws IOException {
    writer.append(StringUtils.join(csvRowStrings, ","));
    writer.append("\n");
}

From source file:me.ardacraft.blocksapi.helper.LangHelper.java

public static void writeLangFile() {
    File out = FileHelper.externalConfigFile("assets/acblocks/lang", "en_US.lang");
    try {//from w w w  .j av a 2 s .  co  m
        FileWriter writer = new FileWriter(out);
        Collections.sort(entries);
        for (String s : entries) {
            writer.write(s);
            writer.append("\n");
        }
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    entries.clear();
}

From source file:net.itransformers.bgpPeeringMap.BgpPeeringMap.java

public static void discover() throws Exception {
    Map<String, String> settings = loadProperties(new File(settingsFile));
    logger.info("Settings" + settings.toString());

    String folderPlaceholder = settings.get("output.dir");

    File outputDir = new File(projectDir + File.separator + folderPlaceholder, label);

    System.out.println(outputDir.getAbsolutePath());
    boolean result = outputDir.mkdir();
    File graphmlDir = new File(outputDir, "undirected");

    result = outputDir.mkdir();// w  w w. j  a  va2s  .c  o  m
    XsltTransformer transformer = new XsltTransformer();
    logger.info("SNMP walk start");
    byte[] rawData = snmpWalk(settings);
    logger.info("SNMP walk end");
    File rawDataFile = new File(outputDir, "raw-data-bgpPeeringMap.xml");
    FileUtils.writeStringToFile(rawDataFile, new String(rawData));

    logger.info("Raw-data written to a file in folder " + outputDir);
    logger.info("First-transformation has started with xsltTransformator " + settings.get("xsltFileName1"));

    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();
    File xsltFileName1 = new File(projectDir, settings.get("xsltFileName1"));
    ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData);
    transformer.transformXML(inputStream1, xsltFileName1, outputStream1, settings);
    logger.info("First transformation finished");
    File intermediateDataFile = new File(outputDir, "intermediate-bgpPeeringMap.xml");

    FileUtils.writeStringToFile(intermediateDataFile, new String(outputStream1.toByteArray()));
    logger.trace("First transformation output");

    logger.trace(outputStream1.toString());
    logger.info("Second transformation started with xsltTransformator " + settings.get("xsltFileName2"));

    ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
    File xsltFileName2 = new File(projectDir, settings.get("xsltFileName2"));
    ByteArrayInputStream inputStream2 = new ByteArrayInputStream(outputStream1.toByteArray());
    transformer.transformXML(inputStream2, xsltFileName2, outputStream2, settings);
    logger.info("Second transformation info");
    logger.trace("Second transformation Graphml output");
    logger.trace(outputStream2.toString());

    ByteArrayInputStream inputStream3 = new ByteArrayInputStream(outputStream2.toByteArray());
    ByteArrayOutputStream outputStream3 = new ByteArrayOutputStream();
    File xsltFileName3 = new File(System.getProperty("base.dir"), settings.get("xsltFileName3"));
    transformer.transformXML(inputStream3, xsltFileName3, outputStream3, null);

    File outputFile = new File(graphmlDir, "undirected-bgpPeeringMap.graphml");
    FileUtils.writeStringToFile(outputFile, new String(outputStream3.toByteArray()));
    logger.info("Output Graphml saved in a file in" + graphmlDir);

    //FileUtils.writeStringToFile(nodesFileListFile, "bgpPeeringMap.graphml");
    FileWriter writer = new FileWriter(new File(outputDir, "undirected" + ".graphmls"), true);
    writer.append("undirected-bgpPeeringMap.graphml").append("\n");
    writer.close();

}

From source file:Main.java

public static void writeCSV(String phoneNo, String Message) {
    File root = Environment.getExternalStorageDirectory();
    File csvFile = new File(root, "/adspammer/log.csv");
    FileWriter writer = null;
    try {/*from  ww w  .j  av a 2  s . com*/
        writer = new FileWriter(csvFile, true);

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd @ HH:mm:ss");
        Date date = new Date();
        System.out.println(dateFormat.format(date));

        writer.append(dateFormat.format(date).toString());
        writer.append(',');
        writer.append(phoneNo);
        writer.append(',');
        writer.append(Message);
        writer.append('\n');

        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.moss.appsnap.keeper.freedesktop.FreeDesktopAppHandler.java

public static void writeDesktopFile(String name, File location, File target) throws IOException {
    FileWriter writer = new FileWriter(location);
    writer.append("[Desktop Entry]\n");
    writer.append("Type=Application\n");
    writer.append("Name=");
    writer.append(name);/*from w w w. j  a  v  a  2 s.com*/
    writer.append("\n");
    writer.append("Exec=");
    writer.append(SHELL);
    writer.append(" ");
    writer.append(target.getAbsolutePath());
    writer.append("\n");
    writer.flush();
    writer.close();
}

From source file:au.org.ala.spatial.util.UploadSpatialResource.java

public static String loadCreateStyle(String url, String extra, String username, String password, String name) {
    System.out.println("loadCreateStyle url:" + url);
    System.out.println("name:" + name);

    String output = "";

    HttpClient client = new HttpClient();
    client.setConnectionTimeout(10000);// w  w w  .j a  va  2  s. c o m
    client.setTimeout(60000);

    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    PostMethod post = new PostMethod(url);
    post.setDoAuthentication(true);

    // Execute the request
    try {
        // Request content will be retrieved directly
        // from the input stream
        File file = File.createTempFile("sld", "xml");
        FileWriter fw = new FileWriter(file);
        fw.append("<style><name>" + name + "</name><filename>" + name + ".sld</filename></style>");
        fw.close();
        RequestEntity entity = new FileRequestEntity(file, "text/xml");
        post.setRequestEntity(entity);

        int result = client.executeMethod(post);

        output = result + ": " + post.getResponseBodyAsString();

    } catch (Exception e) {
        e.printStackTrace(System.out);
        output = "0: " + e.getMessage();
    } finally {
        // Release current connection to the connection pool once you are done
        post.releaseConnection();
    }

    return output;
}

From source file:au.org.ala.spatial.util.UploadSpatialResource.java

public static String assignSld(String url, String extra, String username, String password, String data) {
    System.out.println("assignSld url:" + url);
    System.out.println("data:" + data);

    String output = "";

    HttpClient client = new HttpClient();
    client.setConnectionTimeout(10000);//w  ww .  ja  v  a  2s  .c  om
    client.setTimeout(60000);

    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    PutMethod put = new PutMethod(url);
    put.setDoAuthentication(true);

    // Execute the request
    try {
        // Request content will be retrieved directly
        // from the input stream
        File file = File.createTempFile("sld", "xml");
        System.out.println("file:" + file.getPath());
        FileWriter fw = new FileWriter(file);
        fw.append(data);
        fw.close();
        RequestEntity entity = new FileRequestEntity(file, "text/xml");
        put.setRequestEntity(entity);

        int result = client.executeMethod(put);

        output = result + ": " + put.getResponseBodyAsString();

    } catch (Exception e) {
        output = "0: " + e.getMessage();
        e.printStackTrace(System.out);
    } finally {
        // Release current connection to the connection pool once you are done
        put.releaseConnection();
    }

    return output;
}

From source file:org.ala.spatial.util.UploadSpatialResource.java

public static String loadCreateStyle(String url, String extra, String username, String password, String name) {
    System.out.println("loadCreateStyle url:" + url);
    System.out.println("name:" + name);

    String output = "";

    HttpClient client = new HttpClient();

    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    PostMethod post = new PostMethod(url);
    post.setDoAuthentication(true);//from  ww w. j a  v a2  s  .c  o  m

    // Execute the request
    try {
        // Request content will be retrieved directly
        // from the input stream
        File file = File.createTempFile("sld", "xml");
        System.out.println("file:" + file.getPath());
        FileWriter fw = new FileWriter(file);
        fw.append("<style><name>" + name + "</name><filename>" + name + "</filename></style>");
        fw.close();
        RequestEntity entity = new FileRequestEntity(file, "text/xml");
        post.setRequestEntity(entity);

        int result = client.executeMethod(post);

        // get the status code
        System.out.println("Response status code: " + result);

        // Display response
        System.out.println("Response body: ");
        System.out.println(post.getResponseBodyAsString());

        output += result;

    } catch (Exception e) {
        System.out.println("Something went wrong with UploadSpatialResource");
        e.printStackTrace(System.out);
    } finally {
        // Release current connection to the connection pool once you are done
        post.releaseConnection();
    }

    return output;
}

From source file:org.ala.spatial.util.UploadSpatialResource.java

public static String assignSld(String url, String extra, String username, String password, String data) {
    System.out.println("assignSld url:" + url);
    System.out.println("data:" + data);

    String output = "";

    HttpClient client = new HttpClient();

    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    PutMethod put = new PutMethod(url);
    put.setDoAuthentication(true);// w ww  .j av a 2 s .  com

    // Execute the request
    try {
        // Request content will be retrieved directly
        // from the input stream
        File file = File.createTempFile("sld", "xml");
        System.out.println("file:" + file.getPath());
        FileWriter fw = new FileWriter(file);
        fw.append(data);
        fw.close();
        RequestEntity entity = new FileRequestEntity(file, "text/xml");
        put.setRequestEntity(entity);

        int result = client.executeMethod(put);

        // get the status code
        System.out.println("Response status code: " + result);

        // Display response
        System.out.println("Response body: ");
        System.out.println(put.getResponseBodyAsString());

        output += result;

    } catch (Exception e) {
        System.out.println("Something went wrong with UploadSpatialResource");
        e.printStackTrace(System.out);
    } finally {
        // Release current connection to the connection pool once you are done
        put.releaseConnection();
    }

    return output;
}

From source file:com.moss.appsnap.keeper.freedesktop.FreeDesktopAppHandler.java

public static void writeLaunchScript(boolean isKeeper, String launchCommand, File scriptLocation,
        final PosixFifoSocketAddress fifoSocketServer) throws IOException {
    FileWriter writer = new FileWriter(scriptLocation);
    writer.append("#!" + SHELL + "\n\n");

    if (!isKeeper) {
        {// WRITE THE FIFO SOCKETS FUNCTION
            Reader functionReader = new InputStreamReader(PosixFifoMisc.sendFifoSocketMessageBashFunction());
            char[] b = new char[1024];

            for (int x = functionReader.read(b); x != -1; x = functionReader.read(b)) {
                writer.write(b, 0, x);/*from w  w  w  .j a v a 2s .c o  m*/
            }
        }

        {
            // WRITE THE POLLING CALL TO THE KEEPER
            final char EOL = '\n';
            writer.append(EOL + "CONTROL=" + fifoSocketServer.controlPipe().getAbsolutePath() + "\n" + "DIR="
                    + fifoSocketServer.socketsDir().getAbsolutePath() + EOL + "" + EOL
                    + "xmessage \"Checking for updates...\" -buttons \"\" -center -title \"Please Wait...\" &"
                    + EOL + "DIALOG=$!" + EOL + "" + EOL
                    + "RESPONSE=`echo -n \"LAUNCH_POLL\" | sendFifoSocketMessage $CONTROL $DIR`" + EOL + ""
                    + EOL + "echo \"RESPONSE: $RESPONSE\"" + EOL + "" + EOL + "kill $DIALOG" + EOL + "" + EOL
                    + "if [ \"$RESPONSE\" != \"OK\" ] " + EOL + "then" + EOL
                    + "   xmessage -center -buttons OK -default OK  \"Polling error: $RESPONSE\"" + EOL
                    + "   exit 1;" + EOL + "fi" + EOL + "" + EOL);
        }
        writer.append(launchCommand);
    } else {
        writer.append("while [ 1 ]; do \n");
        writer.append(launchCommand);
        writer.append('\n');
        writer.append("RESULT=$?\n");
        writer.append("if [ $RESULT != 0 ]; then echo \"Error: keeper quit with return $RESULT\"; exit; fi\n");
        writer.append("done");
    }

    writer.flush();
    writer.close();

}