List of usage examples for java.io OutputStreamWriter write
public void write(int c) throws IOException
From source file:com.googlecode.noweco.calendar.test.CalendarClientTest.java
@Test @Ignore//w w w. j ava 2s . c o m public void test() throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); // if (google || chandlerproject) { // HttpParams params = httpclient.getParams(); // ConnRouteParams.setDefaultProxy(params, new HttpHost("ecprox.bull.fr")); // } HttpEntityEnclosingRequestBase httpRequestBase = new HttpEntityEnclosingRequestBase() { @Override public String getMethod() { return "PROPFIND"; } }; BasicHttpEntity entity = new BasicHttpEntity(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayOutputStream); // outputStreamWriter.write( "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"> <D:prop> <D:displayname/> <D:principal-collection-set/> <calendar-home-set xmlns=\"urn:ietf:params:xml:ns:caldav\"/> </D:prop> </D:propfind>"); outputStreamWriter.close(); entity.setContent(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); httpRequestBase.setEntity(entity); httpRequestBase.setURI(new URI("/dav/collection/gael.lalire@bull.com/")); if (google) { httpRequestBase.setURI(new URI("/calendar/dav/gael.lalire@gmail.com/user/")); } if (chandlerproject) { httpRequestBase.setURI(new URI("/dav/collection/8de93530-8796-11e0-82b8-d279848d8f3e")); } if (apple) { httpRequestBase.setURI(new URI("/")); } HttpHost target = new HttpHost("localhost", 8080); if (google) { target = new HttpHost("www.google.com", 443, "https"); } if (chandlerproject) { target = new HttpHost("hub.chandlerproject.org", 443, "https"); } if (apple) { target = new HttpHost("localhost", 8008, "http"); } httpRequestBase.setHeader("Depth", "0"); String userpass = null; if (apple) { userpass = "admin:admin"; } httpRequestBase.setHeader("authorization", "Basic " + Base64.encodeBase64String(userpass.getBytes())); HttpResponse execute = httpclient.execute(target, httpRequestBase); System.out.println(Arrays.deepToString(execute.getAllHeaders())); System.out.println(execute.getStatusLine()); System.out.println(EntityUtils.toString(execute.getEntity())); }
From source file:com.athena.chameleon.engine.core.analyzer.parser.Parser.java
/** * <pre>/*from w ww.ja v a 2 s. com*/ * XML ? ?? . * </pre> * @param file * @param xmlData * @throws IOException */ protected void rewrite(File file, String xmlData) throws IOException { OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); output.write(xmlData); IOUtils.closeQuietly(output); }
From source file:com.thoughtworks.go.server.dashboard.GoDashboardPipelineGroup.java
public String etag() { try {/*from ww w. j a va 2s. com*/ 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:com.twinsoft.convertigo.engine.print.PrintHTML.java
@Override public String print(String location) throws IOException, EngineException, SAXException, TransformerFactoryConfigurationError, TransformerException, ParserConfigurationException { super.print(location); out.close();/* w w w. j a v a2s . c o m*/ updateStatus("Create Ressources Directory", 70); //get the dom Document fopResult = XMLUtils.parseDOM(outputFile); Element root = fopResult.getDocumentElement(); String templateFileName = Engine.TEMPLATES_PATH + "/doc/doc.html.xsl"; File htmlFile = new File(templateFileName); Source xsltSrc = new StreamSource(new FileInputStream(htmlFile), localizedDir); //create the ressources repository String ressourcesFolder = outputFolder + "/ressources"; File repository = new File(ressourcesFolder); if (!repository.exists()) { repository.mkdir(); } //export images NodeList images = fopResult.getElementsByTagName("image"); Node image; String attrImg, attrImgName; InputStream imagesIn; OutputStream imagesOut; for (int i = 0; i < images.getLength(); i++) { image = images.item(i); attrImg = image.getAttributes().getNamedItem("url").getTextContent(); attrImgName = attrImg.replaceAll("(.*)/", ""); image.getAttributes().getNamedItem("url").setTextContent(attrImgName); imagesIn = new FileInputStream(attrImg); imagesOut = new FileOutputStream(ressourcesFolder + "/" + attrImgName); org.apache.commons.io.IOUtils.copy(imagesIn, imagesOut); imagesIn.close(); imagesOut.close(); } //export css FileInputStream cssIn = new FileInputStream(Engine.TEMPLATES_PATH + "/doc/style.css"); FileOutputStream cssOut = new FileOutputStream(ressourcesFolder + "/style.css"); org.apache.commons.io.IOUtils.copy(cssIn, cssOut); cssIn.close(); cssOut.close(); updateStatus("HTML Transformation", 85); // transformation of the dom Transformer xslt = TransformerFactory.newInstance().newTransformer(xsltSrc); Element xsl = fopResult.createElement("xsl"); xslt.transform(new DOMSource(fopResult), new DOMResult(xsl)); fopResult.removeChild(root); fopResult.appendChild(xsl.getFirstChild()); //write the dom String newOutputFileName = outputFolder + "/" + projectName + ".html"; outputFile = new File(newOutputFileName); out = new FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); OutputStreamWriter output = new OutputStreamWriter(out); output.write(XMLUtils.prettyPrintDOM(fopResult)); output.close(); //remove the temp file new File(outputFileName).delete(); updateStatus("Printing finished", 100); return newOutputFileName; }
From source file:org.compose.mobilesdk.android.ServerRequestTask.java
public String doPUTRequest(URL requestUrl) { String responseString = null; try {/*from ww w. j av a 2s .c om*/ HttpURLConnection httpCon = (HttpURLConnection) requestUrl.openConnection(); httpCon.setDoOutput(true); httpCon.setDoInput(true); httpCon.setRequestMethod("PUT"); httpCon.setRequestProperty("Content-Type", "application/json"); httpCon.setRequestProperty("Authorization", header_parameters); httpCon.setRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) "); httpCon.setRequestProperty("Accept", "*/*"); OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream()); out.write("" + this.message); out.close(); if (DEBUG) { BufferedReader in = null; if (httpCon.getErrorStream() != null) in = new BufferedReader(new InputStreamReader(httpCon.getErrorStream())); else in = new BufferedReader(new InputStreamReader(httpCon.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { Log.i(DEBUG_INFO, inputLine); } in.close(); } } catch (Exception e) { e.printStackTrace(); } return responseString; }
From source file:com.EconnectTMS.CustomerInformation.java
public void Run(String IncomingMessage, String intid) throws MalformedURLException, UnsupportedEncodingException, IOException { try {//from w w w . ja v a2 s . c o m strRecievedData = IncomingMessage.split("#"); processingcode = strRecievedData[0]; switch (processingcode) { case "800000": AccountNumber = strRecievedData[1]; URL url = new URL(CUSTOMER_DETAILS_URL); Map<String, String> params = new LinkedHashMap<>(); params.put("username", CUSTOMER_DETAILS_USERNAME); params.put("password", CUSTOMER_DETAILS_PASSWORD); params.put("source", CUSTOMER_DETAILS_SOURCE_ID); params.put("account", AccountNumber); postData = new StringBuilder(); for (Map.Entry<String, String> param : params.entrySet()) { if (postData.length() != 0) { postData.append('&'); } postData.append(URLEncoder.encode(param.getKey(), "UTF-8")); postData.append('='); postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); } urlParameters = postData.toString(); conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(urlParameters); writer.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { result += line; } writer.close(); reader.close(); JSONObject respobj = new JSONObject(result); if (respobj.has("FSTNAME") || respobj.has("MIDNAME") || respobj.has("LSTNAME")) { if (respobj.has("FSTNAME")) { fname = respobj.get("FSTNAME").toString().toUpperCase() + ' '; } if (respobj.has("MIDNAME")) { mname = respobj.get("MIDNAME").toString().toUpperCase() + ' '; } if (respobj.has("LSTNAME")) { lname = respobj.get("LSTNAME").toString().toUpperCase() + ' '; } strCustomerName = fname + mname + lname; } else { strCustomerName = " "; } System.out.println("result:" + result); func.SendPOSResponse(strCustomerName + "#", intid); return; default: break; } } catch (Exception ex) { strCustomerName = ""; func.log("\nSEVERE CustomerInformation() :: " + ex.getMessage() + "\n" + func.StackTraceWriter(ex), "ERROR"); } }
From source file:com.thoughtworks.go.server.dashboard.AbstractDashboardGroup.java
protected String digest(String permissionsSegment) { try {// www .j a v a 2 s. c o m MessageDigest digest = DigestUtils.getSha256Digest(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new DigestOutputStream(new NullOutputStream(), digest)); outputStreamWriter.write(getClass().getSimpleName()); outputStreamWriter.write("$"); outputStreamWriter.write(name()); outputStreamWriter.write("/"); outputStreamWriter.write(permissionsSegment); outputStreamWriter.write("["); for (GoDashboardPipeline pipeline : allPipelines()) { outputStreamWriter.write(pipeline.cacheSegment()); outputStreamWriter.write(","); } outputStreamWriter.write("]"); outputStreamWriter.flush(); return Hex.encodeHexString(digest.digest()); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.google.wave.api.oauth.impl.OpenSocialHttpClient.java
/** * Executes a request and writes all data in the request's body to the * output stream./* ww w . j a v a 2 s. c o m*/ * * @param method * @param url * @param body * @return Response message */ private OpenSocialHttpResponseMessage send(String method, OpenSocialUrl url, String contentType, String body) throws IOException { HttpURLConnection connection = null; try { connection = getConnection(method, url, contentType); if (body != null) { OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); out.write(body); out.flush(); out.close(); } return new OpenSocialHttpResponseMessage(method, url, connection.getInputStream(), connection.getResponseCode()); } catch (IOException e) { throw new IOException( "Container returned status " + connection.getResponseCode() + " \"" + e.getMessage() + "\""); } }
From source file:com.omertron.themoviedbapi.tools.WebBrowser.java
public static String request(URL url, String jsonBody, boolean isDeleteRequest) throws MovieDbException { StringWriter content = null;/*from www.j a v a2 s. co m*/ try { content = new StringWriter(); BufferedReader in = null; HttpURLConnection cnx = null; OutputStreamWriter wr = null; try { cnx = (HttpURLConnection) openProxiedConnection(url); // If we get a null connection, then throw an exception if (cnx == null) { throw new MovieDbException(MovieDbException.MovieDbExceptionType.CONNECTION_ERROR, "No HTTP connection could be made.", url); } if (isDeleteRequest) { cnx.setDoOutput(true); cnx.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); cnx.setRequestMethod("DELETE"); } sendHeader(cnx); if (StringUtils.isNotBlank(jsonBody)) { cnx.setDoOutput(true); wr = new OutputStreamWriter(cnx.getOutputStream()); wr.write(jsonBody); } readHeader(cnx); // http://stackoverflow.com/questions/4633048/httpurlconnection-reading-response-content-on-403-error if (cnx.getResponseCode() >= 400) { in = new BufferedReader(new InputStreamReader(cnx.getErrorStream(), getCharset(cnx))); } else { in = new BufferedReader(new InputStreamReader(cnx.getInputStream(), getCharset(cnx))); } String line; while ((line = in.readLine()) != null) { content.write(line); } } finally { if (wr != null) { wr.flush(); wr.close(); } if (in != null) { in.close(); } if (cnx instanceof HttpURLConnection) { ((HttpURLConnection) cnx).disconnect(); } } return content.toString(); } catch (IOException ex) { throw new MovieDbException(MovieDbException.MovieDbExceptionType.CONNECTION_ERROR, null, url, ex); } finally { if (content != null) { try { content.close(); } catch (IOException ex) { LOG.debug("Failed to close connection: " + ex.getMessage()); } } } }
From source file:de.zib.scalaris.examples.wikipedia.plugin.fourcaast.FourCaastAccounting.java
protected void pushSdrToServer(final WikiPageBeanBase page) { if (!page.getServiceUser().isEmpty()) { final String sdr = createSdr(page); // System.out.println("Sending sdr...\n" + sdr); try {/*from w w w . j a va 2s. c o m*/ HttpURLConnection urlConn = (HttpURLConnection) accountingServer.openConnection(); urlConn.setDoOutput(true); urlConn.setRequestMethod("PUT"); OutputStreamWriter out = new OutputStreamWriter(urlConn.getOutputStream()); out.write(sdr); out.close(); //read the result from the server (necessary for the request to be send!) BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = in.readLine()) != null) { sb.append(line + '\n'); } // System.out.println(sb.toString()); in.close(); } catch (ProtocolException e) { throw new RuntimeException(e); } catch (IOException e) { e.printStackTrace(); } } }