Example usage for java.io BufferedWriter flush

List of usage examples for java.io BufferedWriter flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:mainserver.Server.java

public static void sendMessage(String text, Socket clientSocket) {
    try {//from w w w  .  j  a  v  a 2s .com
        BufferedWriter outputToServer = new BufferedWriter(
                new OutputStreamWriter(clientSocket.getOutputStream()));
        outputToServer.write(text + "\r\n");
        outputToServer.flush();

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

}

From source file:com.thinkit.operationsys.util.FileUtil.java

/**
 * ?//from  ww w.  j a  v  a  2  s .  c  o m
 *
 * @param fileName
 * @param data
 */
public static void write(String fileName, String data) {
    BufferedWriter bw = null;
    try {
        //         String name = getName(link) + "analyze.txt";
        bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName)));
        bw.write(data);
        bw.flush();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (null != bw) {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.book.jtm.chap03.HttpClientDemo.java

private static void writeParams(OutputStream output, List<NameValuePair> paramsList) throws IOException {
    StringBuilder paramStr = new StringBuilder();
    for (NameValuePair pair : paramsList) {
        if (!TextUtils.isEmpty(paramStr)) {
            paramStr.append("&");
        }/*from   w  w  w .j  a  v a2  s. c  o m*/
        paramStr.append(URLEncoder.encode(pair.getName(), "UTF-8"));
        paramStr.append("=");
        paramStr.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
    }

    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8"));
    // ??
    writer.write(paramStr.toString());
    writer.flush();
    writer.close();
}

From source file:com.sp.Parser.Utils.java

public static synchronized void Send_TCP(Socket s, String JsonFormattedResponse) throws IOException {

    BufferedWriter outToClient = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(), "UTF-8"));
    outToClient.write(JsonFormattedResponse);
    outToClient.flush();
}

From source file:es.sotileza.plugin.utils.Utilidades.java

public static void addXml(String xml, String linea) throws IOException {
    FileWriter output = new FileWriter(xml, true);
    BufferedWriter writer = new BufferedWriter(output);
    writer.write(linea + "\n");
    writer.flush();
}

From source file:net.amigocraft.mpt.Main.java

public static void initializeRepoStore(File file) {
    log.info("Initializing local repository store...");
    try {/*from w ww . j  a v a  2  s  .  c  o m*/
        MiscUtil.lockStores();
        JSONObject repos = new JSONObject(); // create an empty array
        repoStore = new JSONObject(); // create an empty object
        repoStore.put("repositories", repos); // add the array to it
        if (!file.getParentFile().exists())
            file.getParentFile().mkdir();
        file.createNewFile(); // create the file
        BufferedWriter writer = new BufferedWriter(new FileWriter(file)); // get a writer
        writer.write(JSONPrettyPrinter.toJSONString(repoStore)); // convert the JSON object to a string and write it
        writer.flush();
    } catch (IOException ex) {
        ex.printStackTrace();
        log.severe("Failed to initialize repository store!");
    } catch (MPTException ex) {
        log.severe(ex.getMessage());
    }
    MiscUtil.unlockStores();
}

From source file:Main.java

public static boolean createFile(String name) {
    File outfile = new File(name);
    BufferedWriter writer = null;
    if (!outfile.isFile()) {
        try {/*from  ww  w. ja v a2  s .co m*/
            outfile.createNewFile();
            writer = new BufferedWriter(new FileWriter(outfile));
            writer.write(
                    "#_*_ coding: iso8859_1\n# Script API\n\nfrom com.android.python import AndroidDriver\n\n");
            writer.flush();
            return true;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}

From source file:net.amigocraft.mpt.Main.java

public static void initializePackageStore(File file) {
    log.info("Initializing local package store...");
    try {//from   w ww .  j  ava2s. c  o m
        MiscUtil.lockStores();
        JSONObject packages = new JSONObject(); // create an empty array
        packageStore = new JSONObject(); // create an empty object
        packageStore.put("packages", packages); // add the array to it
        try {
            if (!file.getParentFile().exists())
                file.getParentFile().mkdir();
            file.createNewFile(); // create the file
            BufferedWriter writer = new BufferedWriter(new FileWriter(file)); // get a writer
            writer.write(JSONPrettyPrinter.toJSONString(packageStore)); // convert the JSON object to a string and write it
            writer.flush();
        } catch (IOException ex) {
            ex.printStackTrace();
            log.severe("Failed to initialize package store!");
        }
        MiscUtil.unlockStores();
    } catch (MPTException ex) {
        log.severe(ex.getMessage());
    }
}

From source file:Main.java

public static void write(File file, String data) {
    BufferedWriter out = null;
    try {/*from w  w w  . ja v  a 2  s. c o m*/
        out = new BufferedWriter(new FileWriter(file), 1024);
        out.write(data);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            try {
                out.flush();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.openmrs.module.report.util.FileUtils.java

public static void WriteStringToFile(String str, String file) {

    try {//w w  w . j a  v a 2 s .  co m
        BufferedWriter output = new BufferedWriter(new FileWriter(file));
        output.write(str);
        output.flush();
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}