List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out)
From source file:org.acra.HttpUtils.java
/** * Send an HTTP(s) request with POST parameters. * //from ww w .j a va 2 s .c o m * @param parameters * @param url * @throws UnsupportedEncodingException * @throws IOException * @throws KeyManagementException * @throws NoSuchAlgorithmException */ 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()); Log.d(LOG_TAG, "Posting crash report data"); wr.write(dataBfr.toString()); wr.flush(); wr.close(); Log.d(LOG_TAG, "Reading response"); BufferedReader rd = new BufferedReader(new InputStreamReader(cnx.getInputStream())); String line; while ((line = rd.readLine()) != null) { Log.d(LOG_TAG, line); } rd.close(); }
From source file:com.cloudera.lib.wsrs.JSONMapProvider.java
@Override public void writeTo(Map map, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { Writer writer = new OutputStreamWriter(outputStream); JSONObject.writeJSONString(map, writer); writer.write(ENTER);/*from w w w . j a va 2s . c o m*/ writer.flush(); }
From source file:com.sqs.tq.fdc.TemplateReporter.java
public TemplateReporter(PrintStream ps) { writer = new OutputStreamWriter(ps); }
From source file:boxConnection.SerBoxTelnet.java
public static void runReboot() throws IOException, InterruptedException { Logger.getLogger("SerBoxTelnet").info(ControlMain.getProperty("msg_reboot")); telnet.connect(ControlMain.getActiveBox().getDboxIp()); OutputStream ostream = telnet.getOutputStream(); Writer writer = new OutputStreamWriter(ostream); writer.write(ControlMain.getActiveBox().getLogin() + "\n"); writer.flush();//from w w w. ja va 2 s . c om Thread.sleep(1000); writer.write(ControlMain.getActiveBox().getPassword() + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall sectionsd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall camd2" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall timerd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall timerd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall zapit" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall controld" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("killall nhttpd" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("sleep 3" + "\n"); writer.flush(); Thread.sleep(1000); writer.write("busybox -reboot" + "\n"); writer.flush(); Thread.sleep(1000); closeTelnetSession(); }
From source file:com.thoughtworks.go.server.dashboard.GoDashboardPipelineGroup.java
public String etag() { try {/* w w w . j ava2 s.co m*/ MessageDigest digest = DigestUtils.getSha256Digest(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new DigestOutputStream(new NullOutputStream(), digest)); outputStreamWriter.write(name); outputStreamWriter.write("/"); outputStreamWriter.write(Integer.toString(permissions.hashCode())); outputStreamWriter.write("["); for (Map.Entry<String, GoDashboardPipeline> entry : pipelines.entrySet()) { long lastUpdatedTimeStamp = entry.getValue().getLastUpdatedTimeStamp(); outputStreamWriter.write(entry.getKey()); outputStreamWriter.write(":"); outputStreamWriter.write(Long.toString(lastUpdatedTimeStamp)); } outputStreamWriter.write("]"); outputStreamWriter.flush(); return Hex.encodeHexString(digest.digest()); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:edu.iu.daal_kmeans.regroupallgather.KMUtil.java
/** * Generate centroids and upload to the cDir * /*from w w w.j a v a2 s. co m*/ * @param numCentroids * @param vectorSize * @param configuration * @param random * @param cenDir * @param fs * @throws IOException */ static void generateCentroids(int numCentroids, int vectorSize, Configuration configuration, Path cenDir, FileSystem fs) throws IOException { Random random = new Random(); double[] data = null; if (fs.exists(cenDir)) fs.delete(cenDir, true); if (!fs.mkdirs(cenDir)) { throw new IOException("Mkdirs failed to create " + cenDir.toString()); } data = new double[numCentroids * vectorSize]; for (int i = 0; i < data.length; i++) { data[i] = random.nextDouble() * 1000; } Path initClustersFile = new Path(cenDir, Constants.CENTROID_FILE_NAME); System.out.println("Generate centroid data." + initClustersFile.toString()); FSDataOutputStream out = fs.create(initClustersFile, true); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); for (int i = 0; i < data.length; i++) { if ((i % vectorSize) == (vectorSize - 1)) { bw.write(data[i] + ""); bw.newLine(); } else { bw.write(data[i] + " "); } } bw.flush(); bw.close(); System.out.println("Wrote centroids data to file"); }
From source file:foam.lib.csv.Outputter.java
public Outputter(OutputStream os, OutputterMode mode, boolean outputHeaders) { this(new OutputStreamWriter(os), mode, outputHeaders); }
From source file:com.richtodd.android.repository.JSONUtility.java
public static void saveJSONObject(File file, JSONObject jsonObject) throws RepositoryException { try {/*from w w w.ja v a 2 s.c om*/ String jsonString = jsonObject.toString(); OutputStream out = new FileOutputStream(file); try { Writer writer = new OutputStreamWriter(out); try { writer.write(jsonString); } finally { writer.close(); } } finally { out.close(); } } catch (FileNotFoundException ex) { throw new RepositoryException(ex); } catch (IOException ex) { throw new RepositoryException(ex); } }
From source file:hudson.plugins.sonar.template.SimpleTemplate.java
public void write(FilePath path, String pomName) throws IOException, InterruptedException { FilePath pom = path.child(pomName);/*from ww w. j a va 2 s. com*/ OutputStreamWriter outputStream = new OutputStreamWriter(pom.write()); try { outputStream.write(template); } finally { outputStream.close(); } }
From source file:com.cloudera.lib.wsrs.JSONProvider.java
@Override public void writeTo(JSONStreamAware jsonStreamAware, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { Writer writer = new OutputStreamWriter(outputStream); jsonStreamAware.writeJSONString(writer); writer.write(ENTER);//from w w w .j a v a 2 s. co m writer.flush(); }