List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:de.hshannover.f4.trust.iron.mapserver.communication.http.BasicAccessAuthenticationTest.java
@Override @Before//from w w w . j a v a2s.c om public void setUp() { // ugly, create a properties file "somewhere" for testing try { File f; do { testConf = "irond_test_" + System.nanoTime(); f = new File(testConf); } while (f.exists()); FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw); bw.write("test:test"); bw.flush(); fw.close(); } catch (IOException e) { fail(e.getMessage()); } mServerConf = StubProvider.getServerConfStub(testConf); BasicAuthProvider provider = null; try { provider = new BasicAuthProviderPropImpl(mServerConf); } catch (ProviderInitializationException e) { fail("Cannot initialize the provider!"); } Socket s = new Socket(); mBasicAuth = new BasicChannelAuth(s, provider); }
From source file:com.o2d.pkayjava.editor.CustomExceptionHandler.java
private void writeToFile(String stacktrace, String filename) { try {/*w ww . j a v a 2s.c o m*/ //String localPath = DataManager.getMyDocumentsLocation(); String localPath = "";//DataManager.getInstance().getRootPath(); System.out.println(localPath + File.separator + filename); BufferedWriter bos = new BufferedWriter(new FileWriter(localPath + File.separator + filename)); bos.write(stacktrace); bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.smartitengineering.events.async.api.impl.hub.FileSystemUriStorer.java
@Override public final void storeNextUri(String uri) { try {/*from w w w . j a v a 2s . co m*/ writingInProgressMutex.acquire(); logger.info("New URI being stored"); if (logger.isDebugEnabled()) { logger.debug("URI being stored is " + uri); } BufferedWriter writer = new BufferedWriter(new FileWriter(uriStorage, false)); writer.write(uri); writer.newLine(); writer.flush(); writer.close(); setNextUri(uri); } catch (Exception ex) { logger.error("Could not write to file!", ex); throw new RuntimeException(ex); } finally { writingInProgressMutex.release(); } }
From source file:com.testmax.util.HttpUtil.java
public int postFormdata(String myurl, String param, String xml) { HttpURLConnection httpConn = null; URL url;//from w w w .j av a2 s . c o m int rest = -1; try { url = new URL(myurl); httpConn = (HttpURLConnection) url.openConnection(); httpConn.setRequestProperty("content-type", "text/xml; charset=utf-8"); httpConn.setDoOutput(true); OutputStream os = httpConn.getOutputStream(); BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(os)); osw.write(xml); osw.flush(); osw.close(); rest = httpConn.getResponseCode(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rest; }
From source file:cn.kane.osgi.controller.test.DataPreparor.java
private String parseSqlIn(Resource resource) throws IOException { InputStream is = null;//from w ww.ja v a 2 s .c om try { is = resource.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringWriter sw = new StringWriter(); BufferedWriter writer = new BufferedWriter(sw); for (int c = reader.read(); c != -1; c = reader.read()) { writer.write(c); } writer.flush(); return sw.toString(); } finally { if (is != null) { is.close(); } } }
From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java
public static boolean logout(String server_url) { if (isEmpty(server_url)) { Logd(TAG, "revokSite no server url"); return false; }/*from ww w. j a va2s . c o m*/ if (!server_url.endsWith("/")) server_url += "/"; // get end session endpoint String end_session_endpoint = getEndpointFromConfigOidc("end_session_endpoint", server_url); if (isEmpty(end_session_endpoint)) { Logd(TAG, "logout : could not get end_session_endpoint on server : " + server_url); return false; } // set up connection HttpURLConnection huc = getHUC(end_session_endpoint); // TAZTAG test // huc.setInstanceFollowRedirects(false); huc.setInstanceFollowRedirects(true); // result : follows redirection is ok for taztag huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); huc.setDoOutput(true); huc.setChunkedStreamingMode(0); // prepare parameters List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); try { // write parameters to http connection OutputStream os = huc.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); // get URL encoded string from list of key value pairs String postParam = getQuery(nameValuePairs); Logd("Logout", "url: " + end_session_endpoint); Logd("Logout", "POST: " + postParam); writer.write(postParam); writer.flush(); writer.close(); os.close(); // try to connect huc.connect(); // connexion status int responseCode = huc.getResponseCode(); Logd(TAG, "Logout response: " + responseCode); // if 200 - OK if (responseCode == 200) { return true; } huc.disconnect(); } catch (Exception e) { e.printStackTrace(); return false; } return false; }
From source file:es.ua.dlsi.patch.translation.LocalApertiumTranslator.java
public Set<String> getTranslation(final String input) { Set<String> output = new HashSet<>(); String finalline = ""; // pull from the map if already there try {//from ww w.j a va2 s. c o m String[] command = { "apertium", "-u", langCmd }; ProcessBuilder probuilder = new ProcessBuilder(command); Process process = probuilder.start(); OutputStream stdin = process.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin)); writer.write(input); writer.newLine(); writer.flush(); writer.close(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { finalline += line; } br.close(); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } output.add(finalline); return output; }
From source file:es.ua.dlsi.patch.translation.LocalApertiumTranslator.java
public Map<String, Set<String>> getTranslation(final Set<String> inputset) { Map<String, Set<String>> dictionary = new HashMap<>(); if (!inputset.isEmpty()) { try {/*from w ww . ja va 2 s. c o m*/ StringBuilder sb = new StringBuilder(); List<String> input = new LinkedList<>(inputset); for (String s : input) { sb.append("<p>"); sb.append(s); sb.append("</p>"); } //String[] command = {"apertium", "-u", "-f html", langCmd}; ProcessBuilder probuilder = new ProcessBuilder("apertium", "-u", "-fhtml", langCmd); Process process = probuilder.start(); OutputStream stdin = process.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin)); writer.write(sb.toString()); writer.flush(); writer.close(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; StringBuilder finalline = new StringBuilder(); while ((line = br.readLine()) != null) { finalline.append(line); } br.close(); String finaltranslation = StringEscapeUtils .unescapeHtml3(finalline.toString().replaceAll("\\s<", "<").replaceAll(">\\s", ">") .replaceAll("^<p>", "").replace("</p>", "")); List<String> translations = new LinkedList<>(Arrays.asList(finaltranslation.split("<p>"))); for (int i = 0; i < translations.size(); i++) { if (dictionary.containsKey(input.get(i))) { dictionary.get(input.get(i)).add(translations.get(i)); } else { Set<String> trans_set = new HashSet<>(); trans_set.add(translations.get(i)); dictionary.put(input.get(i), trans_set); } } } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } } return dictionary; }
From source file:playground.johannes.socialnets.GraphStatistics.java
static public Histogram createDegreeHistogram(Graph g, int min, int max, int ignoreWave) { Set<Vertex> vertices = new HashSet<Vertex>(); for (Object o : g.getVertices()) { if (((Vertex) o).getUserDatum(UserDataKeys.ANONYMOUS_KEY) == null) vertices.add((Vertex) o);//from www .ja va 2 s . c o m } DoubleArrayList values = new DoubleArrayList(vertices.size()); DoubleArrayList weights = new DoubleArrayList(vertices.size()); try { BufferedWriter writer = IOUtils.getBufferedWriter(outputDir + ignoreWave + ".weights.txt"); for (Vertex v : vertices) { int k = v.degree(); values.add(k); writer.write(String.valueOf(k)); writer.write("\t"); Integer wave = (Integer) v.getUserDatum(UserDataKeys.SAMPLED_KEY); double w = 1; if (wave == null || k == 0) weights.add(1); else { // w = 1 / (1 - Math.pow((1 - fracVertices),k)); w = 1;// / (Double)v.getUserDatum(UserDataKeys.SAMPLE_PROBA_KEY); weights.add(w); } writer.write(String.valueOf(w)); writer.newLine(); writer.flush(); } writer.close(); } catch (Exception e) { e.printStackTrace(); } if (min < 0 && max < 0) { DoubleArrayList copy = values.copy(); copy.sort(); min = (int) copy.get(0); max = (int) copy.get(values.size() - 1); } Histogram hist = new Histogram(1.0, 0, max); for (int i = 0; i < values.size(); i++) { hist.add(values.get(i), weights.get(i)); } System.out.println("Gamma exponent is estimated to " + estimatePowerLawExponent(values)); return hist; }
From source file:de.highbyte_le.weberknecht.request.view.JsonActionProcessor.java
public boolean processView(HttpServletRequest request, HttpServletResponse response, JsonView action) throws IOException, JSONException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); BufferedWriter writer = null; try {//w ww. j ava2 s .c o m writer = new BufferedWriter(response.getWriter()); JSONWriter jsonWriter = new JSONWriter(writer); action.writeJson(jsonWriter); writer.flush(); } finally { if (writer != null) writer.close(); } return true; }