List of usage examples for java.io ByteArrayOutputStream toString
@Deprecated public synchronized String toString(int hibyte)
From source file:uk.ac.horizon.ubihelper.ui.TestActivity.java
protected void doTest() { DefaultHttpClient httpClient = new DefaultHttpClient(); String url = "http://127.0.0.1:8180/ubihelper"; HttpPost httppost = new HttpPost(url); String request = "[{\"name\":\"magnetic\",\"period\":0.5,\"count\":1,\"timeout\":20}," + "{\"name\":\"accelerometer\",\"period\":0.5,\"count\":1,\"timeout\":20}]"; setText("POST " + url + "\n" + request); try {/*w ww . j av a 2 s. c om*/ httppost.setEntity(new StringEntity(request, "UTF-8")); HttpResponse response = httpClient.execute(httppost); final int status = response.getStatusLine().getStatusCode(); final String message = response.getStatusLine().getReasonPhrase(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); response.getEntity().writeTo(baos); final String resp = baos.toString("UTF-8"); append("\nGot " + status + " (" + message + "): " + resp); } catch (ClientProtocolException e) { e.printStackTrace(); append("\nError: " + e); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); append("\nError: " + e1); } catch (IOException e) { e.printStackTrace(); append("\nError: " + e); } }
From source file:com.mycontacts.resource.UserAddressBookResource.java
@Override public Resource createNew(String newName, InputStream in, Long length, String contentType) throws IOException, ConflictException, NotAuthorizedException, BadRequestException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.copy(in, bout);/*from w w w.j av a 2s .c om*/ String icalData = bout.toString("UTF-8"); Contact cNew = contactManager.createContact(newName, icalData); return new ContactResource(this, cNew); }
From source file:com.temenos.useragent.generic.mediatype.AtomEntryHandler.java
private String getContent(Element element) { try {/*from ww w . ja v a 2 s. c om*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); element.writeTo(baos); return baos.toString("UTF-8"); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.glassmaker.spring.web.FreemarkerMerger.java
@Override public String merge(String templateName, Map<String, ?> data) throws Exception { Template template = cfg.getTemplate(templateName + cardextension, "UTF-8"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(bos, Charset.forName("UTF-8")); template.process(data, out);//from w w w . jav a 2s .c o m return bos.toString("UTF-8"); }
From source file:com.kylinolap.common.util.CliCommandExecutor.java
private Pair<Integer, String> runNativeCommand(String command) throws IOException { String[] cmd = new String[3]; String osName = System.getProperty("os.name"); if (osName.startsWith("Windows")) { cmd[0] = "cmd.exe"; cmd[1] = "/C"; } else {/* www . java2s.c o m*/ cmd[0] = "/bin/bash"; cmd[1] = "-c"; } cmd[2] = command; ProcessBuilder builder = new ProcessBuilder(cmd); builder.redirectErrorStream(true); Process proc = builder.start(); ByteArrayOutputStream buf = new ByteArrayOutputStream(); IOUtils.copy(proc.getInputStream(), buf); String output = buf.toString("UTF-8"); try { int exitCode = proc.waitFor(); return new Pair<Integer, String>(exitCode, output); } catch (InterruptedException e) { throw new IOException(e); } }
From source file:eu.delving.sip.Mockery.java
public String mapping() throws UnsupportedEncodingException { ByteArrayOutputStream os = new ByteArrayOutputStream(); RecMapping.write(os, recMapping);//from w w w.ja va2 s .c o m return os.toString("UTF-8"); }
From source file:org.web4thejob.orm.ListSerializationTest.java
@Test public void datesListTest() throws IOException { final Marshaller marshaller = ContextUtil.getBean(Marshaller.class); Assert.assertNotNull(marshaller);// w ww. java2 s. c o m List<Date> dates = new ArrayList<Date>(); dates.add(new Date()); dates.add(new Date()); dates.add(new Date()); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final Result result = new StreamResult(out); marshaller.marshal(dates, result); System.out.println(out.toString("UTF-8")); }
From source file:com.arcbees.vcs.AbstractVcsApi.java
private HttpResponse doExecuteRequest(HttpClientWrapper httpClient, HttpUriRequest request, Credentials credentials) throws IOException { includeAuthentication(request, credentials); setDefaultHeaders(request);/* www .j a va 2 s. c om*/ HttpResponse httpResponse = httpClient.execute(request); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpURLConnection.HTTP_OK && statusCode != HttpURLConnection.HTTP_CREATED) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); httpResponse.getEntity().writeTo(outputStream); String json = outputStream.toString(CharEncoding.UTF_8); throw new UnexpectedHttpStatusException(statusCode, "Failed to complete request. Status: " + httpResponse.getStatusLine() + '\n' + json); } return httpResponse; }