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:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaEntitesImpl.java

private byte[] exportGraphML(EntiteDto entiteDto, FiltreStatut filtreStatut, Map<String, Boolean> mapIdLiOuvert)
        throws IOException {

    DocumentFactory factory = DocumentFactory.getInstance();
    Element root = factory.createElement("graphml");
    Document document = factory.createDocument(root);
    document.setXMLEncoding("utf-8");

    Element graph = initRoot(root);
    initHeader(root);/*w  ww .  ja  v a 2s  .c o  m*/
    construitTableauStats(graph, entiteDto);
    buildGraphMlTree(graph, entiteDto, mapIdLiOuvert, filtreStatut);
    ajoutLogoMairie(graph);

    ByteArrayOutputStream os_writer = new ByteArrayOutputStream();
    try {
        BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8"));
        document.write(wtr);
        wtr.flush();
        wtr.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return os_writer.toByteArray();
}

From source file:ai.grakn.migration.base.io.MigrationCLI.java

public void writeToSout(String string) {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
    try {//from   w w  w  .  jav  a2  s.  c  o  m
        writer.write(string);
        writer.flush();
    } catch (IOException e) {
        die("Problem writing");
    }
}

From source file:org.wso2.carbon.sample.service.EventsManagerService.java

public String performPostCall(String requestURL, Map<String, String> postDataParams)
        throws HttpException, IOException {

    URL url;/*from ww w .  j a v a 2  s .c om*/
    String response = "";

    url = new URL(requestURL);

    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setReadTimeout(15000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("POST");
    conn.setDoInput(true);
    conn.setDoOutput(true);

    OutputStream os = conn.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
    writer.write(getPostDataString(postDataParams));

    writer.flush();
    writer.close();
    os.close();
    int responseCode = conn.getResponseCode();

    if (responseCode == HttpsURLConnection.HTTP_OK) {
        String line;
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        while ((line = br.readLine()) != null) {
            response += line;
        }
    } else {
        response = "";
        throw new HttpException(responseCode + "");
    }

    return response;
}

From source file:com.pinterest.deployservice.scm.PhabricatorManager.java

private Map<String, Object> queryCLI(String input) throws Exception {
    ProcessBuilder builder;//from ww w  .j  a  va 2  s  .  c o  m
    if (StringUtils.isEmpty(arcrcLocation)) {
        builder = new ProcessBuilder(arcLocation, "call-conduit", String.format("--conduit-uri=%s", urlPrefix),
                "diffusion.historyquery");
    } else {
        builder = new ProcessBuilder(arcLocation, "call-conduit", String.format("--conduit-uri=%s", urlPrefix),
                "diffusion.historyquery", "--arcrc-file", arcrcLocation);
    }
    LOG.debug("Execute arc command: \n{}", builder.command());

    // Redirects error stream to output stream, so have only one input stream to read from
    builder.redirectErrorStream(true);

    // Run command
    Process process = builder.start();

    // Feed the input parameters
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
    writer.write(input);
    writer.flush();
    writer.close();

    InputStream stdout = process.getInputStream();
    String line;
    StringBuilder sb = new StringBuilder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));

    // Read response
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }

    reader.close();

    // We will remove "Waiting for JSON parameters on stdin..." from the output if exists
    String output = sb.toString();
    if (output.startsWith(ARC_OUTPUT_NOTICE)) {
        output = output.substring(ARC_OUTPUT_NOTICE_LEN);
    }
    LOG.debug("arc command output is: \n{}", output);

    GsonBuilder gson = new GsonBuilder();
    return gson.create().fromJson(output, new TypeToken<HashMap<String, Object>>() {
    }.getType());
}

From source file:com.qiqi8226.http.MainActivity.java

private void onBtnPost() {
    new AsyncTask<String, String, Void>() {

        @Override//from w  w  w.j  a  v  a 2s.  c om
        protected Void doInBackground(String... params) {
            URL url;
            try {
                url = new URL(params[0]);
                URLConnection conn = url.openConnection();

                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);

                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
                bw.write("");
                bw.flush();

                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    publishProgress(line);
                }
                br.close();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(String... values) {
            tv.append(values[0] + "\n");
        }
    }.execute("http://www.baidu.com/");
}

From source file:net.sf.mpaxs.spi.computeHost.StartUp.java

/**
 *
 * @param cfg/*from  w  w w.  j av a2s.  c o m*/
 */
public StartUp(Configuration cfg) {
    Settings settings = new Settings(cfg);
    try {
        System.setProperty("java.rmi.server.codebase", settings.getCodebase().toString());
        Logger.getLogger(StartUp.class.getName()).log(Level.INFO, "RMI Codebase at {0}",
                settings.getCodebase().toString());
    } catch (MalformedURLException ex) {
        Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
    }
    File policyFile;
    policyFile = new File(new File(settings.getOption(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR)),
            settings.getPolicyName());
    if (!policyFile.exists()) {
        System.out.println("Did not find security policy, will create default one!");
        policyFile.getParentFile().mkdirs();
        BufferedReader br = new BufferedReader(new InputStreamReader(
                StartUp.class.getResourceAsStream("/net/sf/mpaxs/spi/computeHost/wideopen.policy")));
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(policyFile));
            String s = null;
            while ((s = br.readLine()) != null) {
                bw.write(s + "\n");
            }
            bw.flush();
            bw.close();
            br.close();
            Logger.getLogger(StartUp.class.getName()).log(Level.INFO,
                    "Using security policy at " + policyFile.getAbsolutePath());
        } catch (IOException ex) {
            Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        Logger.getLogger(StartUp.class.getName()).log(Level.INFO,
                "Found existing policy file at " + policyFile.getAbsolutePath());
    }
    System.setProperty("java.security.policy", policyFile.getAbsolutePath());

    System.setProperty("java.net.preferIPv4Stack", "true");

    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }

    Logger.getLogger(StartUp.class.getName()).log(Level.FINE, "Creating host");
    Host h = new Host();
    Logger.getLogger(StartUp.class.getName()).log(Level.FINE, "Configuring host");
    h.configure(cfg);
    Logger.getLogger(StartUp.class.getName()).log(Level.FINE,
            "Setting auth token " + settings.getOption(ConfigurationKeys.KEY_AUTH_TOKEN));
    String at = settings.getOption(ConfigurationKeys.KEY_AUTH_TOKEN);
    h.setAuthenticationToken(UUID.fromString(at));
    Logger.getLogger(StartUp.class.getName()).log(Level.INFO, "Starting host {0}", settings.getHostID());
    h.startComputeHost();
}

From source file:freedots.web.MusicXML2BrailleServlet.java

private void writeResult(Score score, int width, int height, Method method, BrailleEncoding encoding,
        HttpServletResponse resp) throws IOException {
    if (score != null) {
        String[] args = {};//w w w . j  a  v a2  s . c  om
        Options options = new Options(args);

        options.setPageWidth(width);
        options.setPageHeight(height);
        options.setMethod(method);

        final Transcriber transcriber = new Transcriber(options);
        transcriber.setScore(score);
        final String result = transcriber.toString(encoding);

        String title = score.getMovementTitle();
        String filename = "output." + encoding.getExtension();
        if (title != null && !title.isEmpty())
            filename = title + "." + encoding.getExtension();

        if (encoding == BrailleEncoding.HTML) {
            resp.setHeader("Content-Type", "text/html; charset=utf-8");
        } else {
            resp.setHeader("Content-Type", "application/force-download; name=\"" + filename + "\"");
            resp.setHeader("Content-Transfer-Encoding", "binary");
            resp.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        }
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream(), "UTF-8"));

        writer.write(result);
        writer.flush();
        writer.close();
    }
}

From source file:gwap.game.quiz.PlayNHighscoreCommunicationResource.java

private void sendJSONObject(JSONObject jsonObject) {
    OutputStream outstream = null;

    try {/*from  w  ww .  jav  a2 s  .co m*/
        response.setContentType("text/plain");
        outstream = response.getOutputStream();
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outstream));
        jsonObject.writeJSONString(out);
        out.flush();
        outstream.flush();
        outstream.close();

    } catch (IOException e) {
        System.out.println("Exception!");
    }

}

From source file:LVCoref.MMAX2.java

public static void exportSentences(Document d, String filename) {
    BufferedWriter writer = null;
    try {//from  ww  w . ja v a  2s .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/"
            + "sentence" + "\">\n");

    int start = -1;
    int end;
    int sentence_id = 0;
    for (Node n : d.tree) {
        if (n.sentStart)
            start = n.id + 1;
        if (n.sentEnd) {
            end = n.id + 1;
            sentence_id++;

            String span = "word_" + start;
            if (end != start)
                span += "..word_" + end;

            Utils.toWriter(writer, "<markable mmax_level=\"sentence\" id=\"markable_" + sentence_id
                    + "\" span=\"" + span + "\" />\n");
        }
    }
    Utils.toWriter(writer, "</markables>");
    try {
        writer.flush();
        writer.close();
    } catch (IOException ex) {
        Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:at.orz.arangodb.http.JsonSequenceEntity.java

public void writeTo(OutputStream outstream) throws IOException {

    if (outstream == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }//from  w  ww . j  av  a  2s.c om

    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(outstream, "UTF-8"));
        while (it.hasNext()) {
            Object value = it.next();
            gson.toJson(value, writer);
            writer.newLine();
        }
        writer.flush();
    } finally {
    }

}