List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:cc.redpen.formatter.JSONFormatter.java
@Override public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap) throws RedPenException, IOException { BufferedWriter writer = new BufferedWriter(new PrintWriter(pw)); JSONArray errors = new JSONArray(); docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList))); writer.write(errors.toString());//from w w w. j a v a2s . co m writer.flush(); }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
/** * @param vehicleDistances// w w w. j av a2s. c o m * @param iterationFilename */ public static void writeVehicleDistances(Map<Id<Vehicle>, double[]> vehicleDistances, String iterationFilename) { String header = "vehicleId;drivenDistance_m;occupiedDistance_m;emptyDistance_m;revenueDistance_pm"; BufferedWriter bw = IOUtils.getBufferedWriter(iterationFilename); DecimalFormat format = new DecimalFormat(); format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US)); format.setMinimumIntegerDigits(1); format.setMaximumFractionDigits(2); format.setGroupingUsed(false); try { bw.write(header); for (Entry<Id<Vehicle>, double[]> e : vehicleDistances.entrySet()) { double drivenDistance = e.getValue()[0]; double revenueDistance = e.getValue()[1]; double occDistance = e.getValue()[2]; double emptyDistance = drivenDistance - occDistance; bw.newLine(); bw.write(e.getKey().toString() + ";" + format.format(drivenDistance) + ";" + format.format(occDistance) + ";" + format.format(emptyDistance) + ";" + format.format(revenueDistance)); } bw.flush(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.example.socketmobile.android.warrantychecker.network.UserRegistration.java
private Object fetchWarranty(String id, String authString, String query) throws IOException { InputStream is = null;//from w ww.java 2 s. co m RegistrationApiResponse result = null; RegistrationApiErrorResponse errorResult = null; String authHeader = "Basic " + Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP); try { URL url = new URL(baseUrl + id + "/registrations"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(10000 /* milliseconds */); conn.setRequestMethod("POST"); conn.setRequestProperty("Accept", "application/json"); conn.setRequestProperty("Authorization", authHeader); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setDoInput(true); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(query); writer.flush(); writer.close(); os.close(); conn.connect(); int response = conn.getResponseCode(); Log.d(TAG, "Warranty query responded: " + response); switch (response / 100) { case 2: is = conn.getInputStream(); RegistrationApiResponse.Reader reader = new RegistrationApiResponse.Reader(); result = reader.readJsonStream(is); break; case 4: case 5: is = conn.getErrorStream(); RegistrationApiErrorResponse.Reader errorReader = new RegistrationApiErrorResponse.Reader(); errorResult = errorReader.readErrorJsonStream(is); break; } } catch (IOException e) { e.printStackTrace(); return null; } finally { if (is != null) { is.close(); } } return (result != null) ? result : errorResult; }
From source file:com.amgems.uwschedule.api.uw.LoginAuthenticator.java
/** * Collects all cookies from a given response source into a list of NameValuePairs. *///from w ww . j a v a 2 s . c om private List<String> getAuthCookies(HttpURLConnection connection, BufferedWriter writer, List<? extends NameValuePair> postParams) throws IOException { writer.write(NetUtils.toQueryString(postParams)); writer.flush(); return connection.getHeaderFields().get("Set-Cookie"); }
From source file:com.jasonstedman.maven.RequireConfigTransformer.java
public void modifyOutputStream(JarOutputStream jos) throws IOException { logger.info("Creating merged data-main script at war path : " + dataMainPath); logger.info("Merging require configs matching path pattern : " + configFilePattern); logger.info("Using initial define block from : " + initialDefinition); Map<String, Object> configBlock = mergeConfigBlocks(); jos.putNextEntry(new JarEntry(dataMainPath)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(jos)); writer.write("require.config("); writer.write(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(configBlock)); writer.write(");"); writer.newLine();//from w ww. j a v a 2 s . co m writer.write(initBlock); writer.flush(); }
From source file:com.zack6849.superlogger.Main.java
public void log(String line, LoggingCategory category) { BufferedWriter writer = getFile(category).getWriter(); try {/*from ww w.j av a 2s .c om*/ writer.write(getTime() + line); writer.newLine(); writer.flush(); } catch (IOException e) { logger.severe("Error writing line to " + category.getFileName() + " for LoggingCategory." + category.toString()); e.printStackTrace(); } }
From source file:com.myJava.file.driver.remote.ftp.SecuredSocketFactory.java
private void sendCommand(String command, Socket socket, boolean readReply) throws IOException { Logger.defaultLogger().info("Sending FTP command : " + command); // Send Command BufferedWriter out = new BufferedWriter( new OutputStreamWriter(socket.getOutputStream(), client.getControlEncoding())); out.write(command + SocketClient.NETASCII_EOL); out.flush(); if (readReply) { readReply(socket);/*from ww w. j av a 2 s .c om*/ } }
From source file:debop4k.core.io.FilexTest.java
@Test public void bufferedStream() throws Exception { String path = "channel.txt"; try {/* w w w . j a v a 2 s . c o m*/ BufferedWriter writer = Filex.newBufferedWriter(path); try { for (int i = 0; i < 1000; i++) { writer.write(TEST_TEXT); writer.write("\n"); } writer.flush(); } finally { try { if (writer != null) writer.close(); } catch (IOException ignored) { } } List<String> lines = Filex.readAllLines(path); assertThat(lines).isNotEmpty(); assertThat(lines.get(0)).isEqualTo(TEST_TEXT); } finally { Filex.deleteIfExists(path); } }
From source file:com.windigo.http.client.HttpUrlConnectionClient.java
/** * Setup {@link HttpURLConnection} to remote url set some configuration and * body if exist/*from w w w . j a va 2 s.c om*/ * * @param request * @throws MalformedURLException * @throws IOException */ private void setupHttpUrlConnectionClient(HttpURLConnection connection, Request request) throws MalformedURLException, IOException { connection.setDoInput(true); // set headers for request Logger.log("[Request] Found " + request.getHeaders().size() + " header"); addHeaders(request.getHeaders()); if (request.hasBody()) { // if its post request connection.setDoOutput(true); OutputStream os = connection.getOutputStream(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); bw.write(writeBodyParams(request.getBodyParams())); // clean up mess bw.flush(); bw.close(); os.close(); } }
From source file:com.funambol.pushlistener.example.DummyRandomSubmitterLogParser.java
private void dumpEvent(Event event, BufferedWriter writer) throws Exception { writer.write(event.toLine());/*from w w w. j ava2 s . co m*/ writer.newLine(); writer.flush(); }