List of usage examples for java.io OutputStreamWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:com.paramedic.mobshaman.activities.ActualizarInformacionActivity.java
private void updateFile(String fileName, ArrayList<String> inputs) { FileOutputStream outputStream; try {//w ww. j av a 2 s. c o m String separator = System.getProperty("line.separator"); outputStream = openFileOutput(fileName, Context.MODE_PRIVATE); OutputStreamWriter osw = new OutputStreamWriter(outputStream); for (String input : inputs) { osw.append(input); osw.append(separator); } osw.flush(); osw.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.github.nethad.clustermeister.provisioning.cli.Provisioning.java
private void createDefaultConfiguration(String configFilePath) { final File configFile = new File(configFilePath); if (configFile.exists()) { return;/*w w w. j ava 2 s . c om*/ } configFile.getParentFile().mkdirs(); OutputSupplier<OutputStreamWriter> writer = Files.newWriterSupplier(configFile, Charsets.UTF_8); OutputStreamWriter output = null; try { output = writer.getOutput(); output.append(YamlConfiguration.defaultConfiguration()); output.flush(); output.close(); } catch (IOException ex) { throw new RuntimeException(ex); } finally { if (output != null) { try { output.close(); } catch (IOException ex) { // ignore } } } }
From source file:org.nimbustools.messaging.query.AxisBodyWriter.java
public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { final TypeDesc typeDesc = getTypeDescVerySlowly(aClass); final QName qName = typeDesc.getXmlType(); if (qName == null) { throw new WebApplicationException(500); }//from w w w . j av a2 s. c o m String name = qName.getLocalPart(); // responses should not have 'Type' on end of element name. ugly. if (name.endsWith(TYPE_SUFFIX)) { name = name.substring(0, name.length() - TYPE_SUFFIX.length()); } String namespace = getNamespaceUriFromContext(); if (namespace == null) { namespace = qName.getNamespaceURI(); } final OutputStreamWriter writer = new OutputStreamWriter(outputStream); //manually write the xml header deal writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); MessageElement element = new MessageElement(name, "", namespace); try { element.setObjectValue(o); final SerializationContext context = new CleanSerializationContext(writer, namespace); context.setDoMultiRefs(false); context.setPretty(true); element.output(context); } catch (SOAPException e) { throw new WebApplicationException(e); } catch (Exception e) { throw new WebApplicationException(e); } writer.close(); }
From source file:com.adamrosenfield.wordswithcrosses.net.DerStandardDownloader.java
private HttpURLConnection getHttpPostConnection(String url, String postData) throws IOException, MalformedURLException { HttpURLConnection conn = getHttpConnection(url); conn.setRequestMethod("POST"); conn.setDoOutput(true);/*from w w w .j av a 2 s.c o m*/ OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream()); try { osw.append(postData); } finally { osw.close(); } return conn; }
From source file:com.xpn.xwiki.plugin.packaging.AbstractPackageTest.java
private byte[] getEncodedByteArray(String content, String charset) throws IOException { StringReader rdr = new StringReader(content); BufferedReader bfr = new BufferedReader(rdr); ByteArrayOutputStream ostr = new ByteArrayOutputStream(); OutputStreamWriter os = new OutputStreamWriter(ostr, charset); // Voluntarily ignore the first line... as it's the xml declaration String line = bfr.readLine(); os.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\n"); line = bfr.readLine();// ww w . j a v a2 s . c o m while (null != line) { os.append(line); os.append("\n"); line = bfr.readLine(); } os.flush(); os.close(); return ostr.toByteArray(); }
From source file:com.cookbook.cq.dao.util.GsonHttpMessageConverter.java
@Override protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), getCharset(outputMessage.getHeaders())); try {// ww w . ja v a 2 s .c o m if (this.prefixJson) { writer.append("{} && "); } Type typeOfSrc = getType(); if (typeOfSrc != null) { this.gson.toJson(o, typeOfSrc, writer); } else { this.gson.toJson(o, writer); } writer.close(); } catch (JsonIOException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); } }
From source file:org.aludratest.cloud.web.report.SqlBean.java
public void download() { FacesContext context = FacesContext.getCurrentInstance(); // export as CSV - directly send to response to save memory, but use gzip encoding if supported HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); String acceptHeader = request.getHeader("Accept-Encoding"); boolean gzipSupported = acceptHeader != null && acceptHeader.contains("gzip"); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType("text/csv"); response.setCharacterEncoding("UTF-8"); DateFormat dfFileMarker = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); response.setHeader("Content-Disposition", "attachment; filename=acm-data-" + dfFileMarker.format(new Date()) + ".csv"); if (gzipSupported) { response.setHeader("Content-Encoding", "gzip"); }/* w ww . j a v a2 s . com*/ OutputStream out = null; try { out = response.getOutputStream(); if (gzipSupported) { out = new GZIPOutputStream(out, 2048); } OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8"); // write header for (String colName : resultColumns) { writer.append(colName).append(";"); } writer.write("\n"); // write data for (Map<String, String> row : resultRows) { for (String key : resultColumns) { String value = row.get(key); if (value != null) { writer.write(value); } writer.write(";"); } writer.write("\n"); } writer.flush(); writer.close(); } catch (IOException e) { // ignore for now } finally { IOUtils.closeQuietly(out); } context.responseComplete(); }
From source file:com.bcp.bcp.geofencing.GeofenceTransitionsIntentService.java
public File saveGeoFile(String address, String status, String date, String mail, String geofile) { String textToSave = address + "," + status + "," + date + "," + mail; File myFile = null;//from w ww . j av a 2s. c om try { myFile = new File("/sdcard/" + geofile); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(textToSave); myOutWriter.close(); fOut.close(); } catch (Exception e) { e.printStackTrace(); } Log.e("saveGeoFile ", textToSave); return myFile; }
From source file:org.apache.olingo.fit.tecsvc.http.BasicBoundActionsITCase.java
@Test public void boundActionReturningEntityWithNavigationSegInAction() throws Exception { URL url = new URL(SERVICE_URI + "ESTwoKeyNav(PropertyInt16=1,PropertyString='1')/" + "NavPropertyETTwoKeyNavOne/olingo.odata.test1.BAETTwoKeyNavRTETTwoKeyNavParam"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(HttpMethod.POST.name()); connection.setRequestProperty(HttpHeader.ACCEPT, "application/json"); connection.setRequestProperty(HttpHeader.CONTENT_TYPE, "application/json"); connection.setDoOutput(true);/*from w w w .j av a 2s . c o m*/ final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); writer.append("{\"PropertyComp\" : {\"PropertyInt16\" : 30}}"); writer.close(); connection.connect(); assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); final String content = IOUtils.toString(connection.getInputStream()); final String expected = "\"PropertyInt16\":1,\"PropertyString\":\"1\"," + "\"PropertyComp\":{\"PropertyInt16\":30,\"PropertyComp\":" + "{\"PropertyString\":\"StringValue\",\"PropertyBinary\":\"ASNFZ4mrze8=\"," + "\"PropertyBoolean\":true,\"PropertyByte\":255,\"PropertyDate\":\"2012-12-03\"," + "\"PropertyDateTimeOffset\":null,\"PropertyDecimal\":34,\"PropertySingle\":1.79E20," + "\"PropertyDouble\":-1.79E20,\"PropertyDuration\":\"PT6S\"," + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\",\"PropertyInt16\":32767," + "\"PropertyInt32\":2147483647,\"PropertyInt64\":9223372036854775807," + "\"PropertySByte\":127,\"PropertyTimeOfDay\":\"21:05:59\"}}," + "\"PropertyCompNav\":{\"PropertyInt16\":1,\"PropertyComp\":" + "{\"PropertyString\":\"First Resource - positive values\"," + "\"PropertyBinary\":\"ASNFZ4mrze8=\",\"PropertyBoolean\":true," + "\"PropertyByte\":255,\"PropertyDate\":\"2012-12-03\"," + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," + "\"PropertyDecimal\":34,\"PropertySingle\":1.79E20,\"PropertyDouble\":-1.79E20," + "\"PropertyDuration\":\"PT6S\",\"PropertyGuid\":" + "\"01234567-89ab-cdef-0123-456789abcdef\",\"PropertyInt16\":32767," + "\"PropertyInt32\":2147483647,\"PropertyInt64\":9223372036854775807," + "\"PropertySByte\":127,\"PropertyTimeOfDay\":\"21:05:59\"}},\"CollPropertyComp\":[]," + "\"CollPropertyCompNav\":[{\"PropertyInt16\":1}],\"CollPropertyString\":[\"1\",\"2\"]," + "\"PropertyCompTwoPrim\":{\"PropertyInt16\":11,\"PropertyString\":\"11\"}}"; assertTrue(content.contains(expected)); }
From source file:org.apache.zeppelin.notebook.NotebookAuthorization.java
private void saveToFile() { String jsonString;//from www . ja v a2 s. c o m synchronized (authInfo) { NotebookAuthorizationInfoSaving info = new NotebookAuthorizationInfoSaving(); info.authInfo = authInfo; jsonString = gson.toJson(info); } try { File settingFile = new File(filePath); if (!settingFile.exists()) { settingFile.createNewFile(); } FileOutputStream fos = new FileOutputStream(settingFile, false); OutputStreamWriter out = new OutputStreamWriter(fos); out.append(jsonString); out.close(); fos.close(); } catch (IOException e) { LOG.error("Error saving notebook authorization file: " + e.getMessage()); } }