List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out)
From source file:com.wareninja.opensource.common.wsrequest.HttpUtils.java
/** * Send an HTTP(s) request with POST parameters. * // www .j ava 2s . com * @param parameters * @param url * @throws UnsupportedEncodingException * @throws IOException * @throws KeyManagementException * @throws NoSuchAlgorithmException */ public static void doPost(Map<?, ?> parameters, URL url) throws UnsupportedEncodingException, IOException, KeyManagementException, NoSuchAlgorithmException { URLConnection cnx = getConnection(url); // Construct data StringBuilder dataBfr = new StringBuilder(); Iterator<?> iKeys = parameters.keySet().iterator(); while (iKeys.hasNext()) { if (dataBfr.length() != 0) { dataBfr.append('&'); } String key = (String) iKeys.next(); dataBfr.append(URLEncoder.encode(key, "UTF-8")).append('=') .append(URLEncoder.encode((String) parameters.get(key), "UTF-8")); } // POST data cnx.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(cnx.getOutputStream()); if (LOGGING.DEBUG) Log.d(LOG_TAG, "Posting crash report data"); wr.write(dataBfr.toString()); wr.flush(); wr.close(); if (LOGGING.DEBUG) Log.d(LOG_TAG, "Reading response"); BufferedReader rd = new BufferedReader(new InputStreamReader(cnx.getInputStream())); String line; int linecount = 0; while ((line = rd.readLine()) != null) { linecount++; if (linecount <= 2) { if (LOGGING.DEBUG) Log.d(LOG_TAG, line); } } rd.close(); }
From source file:edu.jhu.cvrg.timeseriesstore.opentsdb.TimeSeriesUtility.java
protected static int insertDataPoints(String urlString, List<IncomingDataPoint> points) throws IOException { int code = 0; Gson gson = new Gson(); HttpURLConnection httpConnection = TimeSeriesUtility.openHTTPConnectionPOST(urlString); OutputStreamWriter wr = new OutputStreamWriter(httpConnection.getOutputStream()); String json = gson.toJson(points); wr.write(json);//from w ww . j ava 2 s .co m wr.flush(); wr.close(); code = httpConnection.getResponseCode(); httpConnection.disconnect(); return code; }
From source file:biz.webgate.dominoext.poi.component.kernel.simpleviewexport.CSVExportProcessor.java
public void process2HTTP(ExportModel expModel, UISimpleViewExport uis, HttpServletResponse hsr, DateTimeHelper dth) {/* ww w .ja v a 2s .c o m*/ try { ByteArrayOutputStream csvBAOS = new ByteArrayOutputStream(); OutputStreamWriter csvWriter = new OutputStreamWriter(csvBAOS); CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.DEFAULT); // BUILDING HEADER if (uis.isIncludeHeader()) { for (ExportColumn expColumn : expModel.getColumns()) { csvPrinter.print(expColumn.getColumnName()); } csvPrinter.println(); } // Processing Values for (ExportDataRow expRow : expModel.getRows()) { for (ExportColumn expColumn : expModel.getColumns()) { csvPrinter.print(convertValue(expRow.getValue(expColumn.getPosition()), expColumn, dth)); } csvPrinter.println(); } csvPrinter.flush(); hsr.setContentType("text/csv"); hsr.setHeader("Cache-Control", "no-cache"); hsr.setDateHeader("Expires", -1); hsr.setContentLength(csvBAOS.size()); hsr.addHeader("Content-disposition", "inline; filename=\"" + uis.getDownloadFileName() + "\""); OutputStream os = hsr.getOutputStream(); csvBAOS.writeTo(os); os.close(); } catch (Exception e) { ErrorPageBuilder.getInstance().processError(hsr, "Error during SVE-Generation (CSV Export)", e); } }
From source file:io.scigraph.services.jersey.writers.DelimitedWriter.java
@Override public void writeTo(Graph data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException { try (Writer writer = new OutputStreamWriter(out); CSVPrinter printer = getCsvPrinter(writer)) { List<String> header = newArrayList("id", "label", "categories"); printer.printRecord(header);/*from w w w . ja v a 2s . co m*/ List<String> vals = new ArrayList<>(); for (Vertex vertex : data.getVertices()) { vals.clear(); vals.add(getCurieOrIri(vertex)); String label = getFirst(TinkerGraphUtil.getProperties(vertex, NodeProperties.LABEL, String.class), null); vals.add(label); vals.add(TinkerGraphUtil.getProperties(vertex, Concept.CATEGORY, String.class).toString()); printer.printRecord(vals); } } }
From source file:com.bizo.hive.mr.GenericMR.java
public void map(final InputStream in, final OutputStream out, final Mapper mapper) throws Exception { map(new InputStreamReader(in), new OutputStreamWriter(out), mapper); }
From source file:javasnack.snacks.json.PojoEncodeJackson.java
@Override public void run() { ObjectMapper objectMapper = new ObjectMapper(); try {/*w w w .j ava 2 s .c o m*/ String jsonout = objectMapper.writeValueAsString(new EncodePojo()); System.out.println("--- simple jackson encode ---"); System.out.println(jsonout); String jsonout2 = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(new EncodePojo()); System.out.println("--- default pretty-print jackson encode ---"); System.out.println(jsonout2); System.out.println("--- streaming jackson encode ---"); JsonFactory jsonFactory = objectMapper.getFactory(); Writer out = new OutputStreamWriter(System.out); JsonGenerator jg = jsonFactory.createGenerator(out); jg.setPrettyPrinter(new DefaultPrettyPrinter()); jg.writeStartObject(); jg.writeStringField("message", "success"); jg.writeNumberField("count", 10); jg.writeArrayFieldStart("records"); for (int i = 0; i < 10; i++) { jg.writeObject(new EncodePojo()); Thread.sleep(100); jg.flush(); } jg.writeEndArray(); jg.writeEndObject(); jg.close(); } catch (JsonProcessingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.suren.autotest.web.framework.data.FreemarkerDynamicData.java
@Override public String getValue(String orginData) { StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate(TMP_NAME, orginData); Configuration configuration = new Configuration(); configuration.setTemplateLoader(templateLoader); configuration.setObjectWrapper(new DefaultObjectWrapper()); configuration.setDefaultEncoding("UTF-8"); try {//w w w.j a v a 2 s . co m Template template = configuration.getTemplate(TMP_NAME); ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = new BufferedWriter(new OutputStreamWriter(out)); template.process(globalData, writer); return out.toString("utf-8"); } catch (IOException e) { e.printStackTrace(); } catch (TemplateException e) { e.printStackTrace(); } return null; }
From source file:com.cubusmail.server.services.CubusmailServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fileName = request.getSession().getServletContext().getRealPath(request.getServletPath()); BufferedReader reader = new BufferedReader(new FileReader(fileName)); OutputStream outputStream = response.getOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(outputStream); char[] inBuf = new char[1024]; int len = 0;/*from ww w . jav a2 s .co m*/ try { while ((len = reader.read(inBuf)) > 0) { writer.write(inBuf, 0, len); } } catch (Throwable e) { log.error(e.getMessage(), e); } writer.flush(); writer.close(); outputStream.flush(); outputStream.close(); }
From source file:net.sf.zekr.engine.template.ThemeTemplate.java
/** * Transforms and persists all the theme CSS files if doesn't exists in the cache ( * <tt>Naming.CACHE_DIR</tt>). * //w w w.ja va 2 s.co m * @return result CSS, or null if no transformation done */ public String doTransform() { String retStr = null; String[] cssFileNames = resource.getStrings("theme.css.fileName"); for (int i = 0; i < cssFileNames.length; i++) { File destFile = new File(Naming.getViewCacheDir() + "/" + cssFileNames[i]); // create destination CSS file if it doesn't exist if (!destFile.exists() || destFile.length() == 0) { logger.debug("Theme CSS doesn't exist, will create it: " + cssFileNames[i]); File srcFile = new File( themeData.getPath() + "/" + resource.getString("theme.cssDir") + "/" + cssFileNames[i]); if (config.getTranslation().getDefault() != null) { themeData.process(config.getTranslation().getDefault().locale.getLanguage()); } else { themeData.process("en"); } engine.putAll(themeData.processedProps); try { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(destFile)); retStr = engine.getUpdated(srcFile.getPath()); osw.write(retStr); IOUtils.closeQuietly(osw); } catch (Exception e) { Logger.getLogger(this.getClass()).log(e); } } } return retStr; }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.ServletWriter.java
ServletWriter(OutputStream os) throws IOException { super((os instanceof HttpOutputStream) ? ((HttpOutputStream) os).getWriter(null) : new OutputStreamWriter(os)); this.os = os; }