List of usage examples for java.io StringWriter append
public StringWriter append(char c)
From source file:org.apache.hadoop.hive.ql.exec.FileSinkOperator.java
private void logOutputFormatError(Configuration hconf, HiveException ex) { StringWriter errorWriter = new StringWriter(); errorWriter.append("Failed to create output format; configuration: "); try {// w w w . ja v a 2 s . c om Configuration.dumpConfiguration(hconf, errorWriter); } catch (IOException ex2) { errorWriter.append("{ failed to dump configuration: " + ex2.getMessage() + " }"); } Properties tdp = null; if (this.conf.getTableInfo() != null && (tdp = this.conf.getTableInfo().getProperties()) != null) { errorWriter.append(";\n table properties: { "); for (Map.Entry<Object, Object> e : tdp.entrySet()) { errorWriter.append(e.getKey() + ": " + e.getValue() + ", "); } errorWriter.append('}'); } LOG.error(errorWriter.toString(), ex); }
From source file:edu.harvard.i2b2.navigator.CRCNavigator.java
protected String generateMessageId() { StringWriter strWriter = new StringWriter(); for (int i = 0; i < 20; i++) { int num = getValidAcsiiValue(); // System.out.println("Generated number: " + num + // " char: "+(char)num); strWriter.append((char) num); }//from w w w.j av a 2s. c o m return strWriter.toString(); }
From source file:org.dataconservancy.dcs.access.server.MediciServiceImpl.java
@Override public String getJsonSip(String sipPath) throws InvalidXmlException, FileNotFoundException { ResearchObject sip = new SeadXstreamStaxModelBuilder().buildSip(new FileInputStream(sipPath)); StringWriter tempWriter = new StringWriter(); BagUploadServlet utilServlet = new BagUploadServlet(); utilServlet.siptoJsonConverter().toXML(utilServlet.toQueryResult(sip), tempWriter); tempWriter.append(";" + sipPath); return tempWriter.toString(); }
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
protected String generateMessageId() { StringWriter strWriter = new StringWriter(); for (int i = 0; i < 20; i++) { int num = getValidAcsiiValue(); //System.out.println("Generated number: " + num + " char: "+(char)num); strWriter.append((char) num); }//from w w w . j a v a2 s . c o m return strWriter.toString(); }
From source file:org.sakaiproject.rubrics.logic.RubricsServiceImpl.java
/** * Put the rubric association./*from w w w .j ava2 s . co m*/ * @param targetUri The association href. * @param json The json to post. * @return */ private String putRubricResource(String targetUri, String json, String toolId) throws IOException { log.debug(String.format("PUT to URI '%s' body:", targetUri, json)); HttpURLConnection conn = null; try { URL url = new URL(targetUri); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Content-Length", "" + json.length()); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("PUT"); String cookie = "JSESSIONID=" + sessionManager.getCurrentSession().getId() + "" + System.getProperty(SERVER_ID_PROPERTY); conn.setRequestProperty("Cookie", cookie); conn.setRequestProperty("Authorization", "Bearer " + generateJsonWebToken(toolId)); try (OutputStream os = conn.getOutputStream()) { os.write(json.getBytes("UTF-8")); } // read the response BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; StringWriter result = new StringWriter(); while ((output = br.readLine()) != null) { result.append(output + "\n"); } return result.toString(); } catch (IOException ioException) { log.warn(String.format("Error updating a rubric resource at %s", targetUri), ioException); return null; } finally { if (conn != null) { try { conn.disconnect(); } catch (Exception e) { } } } }
From source file:org.sakaiproject.rubrics.logic.RubricsServiceImpl.java
/** * Posts the rubric association./* w w w . j av a 2s .com*/ * @param json The json to post. * @return */ private String postRubricResource(String targetUri, String json, String toolId, String siteId) throws IOException { log.debug(String.format("Post to URI '%s' body:", targetUri, json)); HttpURLConnection conn = null; try { URL url = new URL(targetUri); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/hal+json; charset=UTF-8"); conn.setRequestProperty("Content-Length", "" + json.length()); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); String cookie = "JSESSIONID=" + sessionManager.getCurrentSession().getId() + "" + System.getProperty(SERVER_ID_PROPERTY); conn.setRequestProperty("Cookie", cookie); if (siteId != null) { conn.setRequestProperty("Authorization", "Bearer " + generateJsonWebToken(toolId, siteId)); } else { conn.setRequestProperty("Authorization", "Bearer " + generateJsonWebToken(toolId)); } try (OutputStream os = conn.getOutputStream()) { os.write(json.getBytes("UTF-8")); os.close(); } // read the response BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; StringWriter result = new StringWriter(); while ((output = br.readLine()) != null) { result.append(output + "\n"); } return result.toString(); } catch (IOException ioException) { log.warn(String.format("Error creating a rubric resource at %s", targetUri), ioException); return null; } finally { if (conn != null) { try { conn.disconnect(); } catch (Exception e) { } } } }
From source file:org.apache.solr.SolrTestCaseJ4.java
/** * Generates a simple <add><doc>... XML String with no options *//*from w w w. j av a2 s .c o m*/ public static String adoc(SolrInputDocument sdoc) { StringWriter out = new StringWriter(512); try { out.append("<add>"); ClientUtils.writeXML(sdoc, out); out.append("</add>"); } catch (IOException e) { throw new RuntimeException("Inexplicable IO error from StringWriter", e); } return out.toString(); }
From source file:org.dataconservancy.dcs.access.server.MediciServiceImpl.java
@Override public String getSipJsonFromBag(String bagPath, String sipPath, String bagitEp) { Client client = Client.create();//w ww . ja va 2s .c o m WebResource webResource = client.resource(bagitEp + "sip/"); File file = new File(bagPath); FileDataBodyPart fdp = new FileDataBodyPart("file", file, MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataMultiPart formDataMultiPart = new FormDataMultiPart(); formDataMultiPart.bodyPart(fdp); com.sun.jersey.api.client.ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA) .post(com.sun.jersey.api.client.ClientResponse.class, formDataMultiPart); try { IOUtils.copy(response.getEntityInputStream(), new FileOutputStream(sipPath + "_0.xml")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // populateKids(sipPath); // fileNos = masterSip.getFiles().size(); ResearchObject sip; StringWriter tempWriter = new StringWriter(); try { sip = new SeadXstreamStaxModelBuilder().buildSip(new FileInputStream(sipPath + "_0.xml")); BagUploadServlet utilServlet = new BagUploadServlet(); utilServlet.siptoJsonConverter().toXML(utilServlet.toQueryResult(sip), tempWriter); tempWriter.append(";" + sipPath); } catch (InvalidXmlException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tempWriter.toString(); }
From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java
/** * Build METS metadata./*from w w w. j a v a2 s .c om*/ * * @return METS metadata * @throws MetsMetadataProcessingException * when some problem with building of the XML with METS metadata occurs */ public MetsMetadata build() throws MetsMetadataProcessingException { StringWriter xmlWriter = new StringWriter(); xmlWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); try { marshaller.marshal(mets, xmlWriter); } catch (JAXBException e) { logger.error("Building XML with metadata failed.", e); throw new MetsMetadataProcessingException(e); } return new MetsMetadata(xmlWriter.toString()); }
From source file:org.epics.archiverappliance.retrieval.DataRetrievalServlet.java
/** * Create a merge dedup consumer that will merge/dedup multiple event streams. * This basically makes sure that we are serving up events in monotonically increasing timestamp order. * @param resp//from ww w .j ava2s . c o m * @param extension * @param useChunkedEncoding * @return * @throws ServletException */ private MergeDedupConsumer createMergeDedupConsumer(HttpServletResponse resp, String extension, boolean useChunkedEncoding) throws ServletException { MergeDedupConsumer mergeDedupCountingConsumer = null; MimeMappingInfo mimemappinginfo = mimeresponses.get(extension); if (mimemappinginfo == null) { StringWriter supportedextensions = new StringWriter(); for (String supportedextension : mimeresponses.keySet()) { supportedextensions.append(supportedextension).append(" "); } throw new ServletException("Cannot generate response of mime-type " + extension + ". Supported extensions are " + supportedextensions.toString()); } else { try { String ctype = mimeresponses.get(extension).contentType; resp.setContentType(ctype); // if(useChunkedEncoding) { // resp.addHeader("Transfer-Encoding", "chunked"); // } logger.info("Using " + mimemappinginfo.mimeresponseClass.getName() + " as the mime response sending " + ctype); MimeResponse mimeresponse = (MimeResponse) mimemappinginfo.mimeresponseClass.newInstance(); HashMap<String, String> extraHeaders = mimeresponse.getExtraHeaders(); if (extraHeaders != null) { for (Entry<String, String> kv : extraHeaders.entrySet()) { resp.addHeader(kv.getKey(), kv.getValue()); } } OutputStream os = resp.getOutputStream(); mergeDedupCountingConsumer = new MergeDedupConsumer(mimeresponse, os); } catch (Exception ex) { throw new ServletException(ex); } } return mergeDedupCountingConsumer; }