List of usage examples for java.nio.charset StandardCharsets UTF_8
Charset UTF_8
To view the source code for java.nio.charset StandardCharsets UTF_8.
Click Source Link
From source file:com.thoughtworks.go.agent.testhelper.AgentBinariesServlet.java
protected void doHead(HttpServletRequest request, HttpServletResponse response) { try {/*w ww . j av a2 s . co m*/ response.setHeader("Content-MD5", resource.getMd5()); final String extraPropertiesHeaderValue = fakeGoServer.getExtraPropertiesHeaderValue(); if (extraPropertiesHeaderValue != null) { response.setHeader(AGENT_EXTRA_PROPERTIES_HEADER, Base64.encodeBase64String(extraPropertiesHeaderValue.getBytes(StandardCharsets.UTF_8))); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:foam.dao.HTTPSink.java
@Override public void put(Object obj, Detachable sub) { HttpURLConnection conn = null; OutputStream os = null;//from www . jav a 2s.com BufferedWriter writer = null; try { Outputter outputter = null; conn = (HttpURLConnection) new URL(url_).openConnection(); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); if (format_ == Format.JSON) { outputter = new foam.lib.json.Outputter(OutputterMode.NETWORK); conn.addRequestProperty("Accept", "application/json"); conn.addRequestProperty("Content-Type", "application/json"); } else if (format_ == Format.XML) { // TODO: make XML Outputter conn.addRequestProperty("Accept", "application/xml"); conn.addRequestProperty("Content-Type", "application/xml"); } conn.connect(); os = conn.getOutputStream(); writer = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8)); writer.write(outputter.stringify((FObject) obj)); writer.flush(); writer.close(); os.close(); // check response code int code = conn.getResponseCode(); if (code != HttpServletResponse.SC_OK) { throw new RuntimeException("Http server did not return 200."); } } catch (Throwable t) { throw new RuntimeException(t); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(os); if (conn != null) { conn.disconnect(); } } }
From source file:io.lavagna.web.helper.GsonHttpMessageConverter.java
public GsonHttpMessageConverter() { super(new MediaType("application", "json", StandardCharsets.UTF_8)); }
From source file:eu.itesla_project.modules.offline.ExportMetricsTool.java
@Override public void run(CommandLine line) throws Exception { String metricsDbName = line.hasOption("metrics-db-name") ? line.getOptionValue("metrics-db-name") : OfflineConfig.DEFAULT_METRICS_DB_NAME; OfflineConfig config = OfflineConfig.load(); MetricsDb metricsDb = config.getMetricsDbFactoryClass().newInstance().create(metricsDbName); String workflowId = line.getOptionValue("workflow"); Path outputFile = Paths.get(line.getOptionValue("output-file")); char delimiter = ';'; if (line.hasOption("delimiter")) { String value = line.getOptionValue("delimiter"); if (value.length() != 1) { throw new RuntimeException("A character is expected"); }// w ww . j ava2 s. c o m delimiter = value.charAt(0); } try (Writer writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) { metricsDb.exportCsv(workflowId, writer, delimiter); } }
From source file:io.codis.nedis.util.NedisUtils.java
public static String bytesToString(byte[] value) { return new String(value, StandardCharsets.UTF_8); }
From source file:com.google.api.server.spi.IoUtilTest.java
@Test public void testGetRequestInputStream() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContent(compress("test".getBytes(StandardCharsets.UTF_8))); request.addHeader("Content-Encoding", "gzip"); InputStream stream = IoUtil.getRequestInputStream(request); assertThat(stream).isInstanceOf(GZIPInputStream.class); assertThat(IoUtil.readStream(stream)).isEqualTo("test"); }
From source file:io.warp10.worf.WorfTemplate.java
public WorfTemplate(Properties config, String templateFilePath) throws WorfException { try {// www . j av a 2 s. c om this.config = config; if (isTemplate(config)) { config.remove("worf.template"); } // load template file Path templatePath = Paths.get(templateFilePath); Charset charset = StandardCharsets.UTF_8; content = new String(Files.readAllBytes(templatePath), charset); } catch (Exception exp) { throw new WorfException("Unable to load template cause=" + exp.getMessage()); } }
From source file:com.none.tom.simplerssreader.opml.OPMLParser.java
public static OPMLFile parse(final InputStream in, final int mode) throws OPMLParserException, XmlPullParserException, IOException { final XmlPullParser parser = Xml.newPullParser(); try {//from w ww . j a v a2 s. c o m parser.setInput(in, null); parser.nextTag(); final String encoding = parser.getInputEncoding(); // <opml> must contain only one attribute; "version" if (TextUtils.isEmpty(encoding) || !encoding.equalsIgnoreCase(StandardCharsets.UTF_8.name()) || parser.getAttributeCount() != 1 || TextUtils.isEmpty(validateVersion(parser, false))) { throw new OPMLParserException(parser); } return parseOPML(parser, mode); } finally { if (in != null) { in.close(); } } }
From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void generateBucketTestData() throws Exception { double meanTest = 10; double meanControl = 10.2; Path path = FileSystems.getDefault().getPath("bucket_test_data.tsv"); try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { Random rand = new Random(); for (int i = 0; i < 1000; i++) { writeBucketTestRecord(out, "test", i, rand.nextGaussian() + meanTest); writeBucketTestRecord(out, "control", i, rand.nextGaussian() + meanControl); }//from ww w.j a v a 2s . c o m } }
From source file:costumetrade.common.util.HttpClientUtils.java
/** * @param url/* w w w . ja va2s .co m*/ * @param ? * @return */ public static String doPost(String url, Map<String, Object> params) { List<BasicNameValuePair> nvps = new ArrayList<>(params.size()); for (String key : params.keySet()) { Object value = params.get(key); if (value != null) { nvps.add(new BasicNameValuePair(key, value.toString())); } } return doPost(url, new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8)); }