List of usage examples for org.apache.commons.io Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.io Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:net.xby1993.common.util.io.HashUtil.java
/** * crc32int, ?./*www. j a v a 2 s . c o m*/ * * Guavacrc32, longJDK */ public static int crc32AsInt(@NotNull String input) { return crc32AsInt(input.getBytes(Charsets.UTF_8)); }
From source file:net.xby1993.common.util.io.HashUtil.java
/** * crc32php64bitlong/* ww w . j a v a2 s . c o m*/ * * Guavacrc32, longJDK */ public static long crc32AsLong(@NotNull String input) { return crc32AsLong(input.getBytes(Charsets.UTF_8)); }
From source file:net.xby1993.common.util.io.HashUtil.java
/** * murmur32, ?//from w w w .j a v a2 s . c om */ public static int murmur32AsInt(@NotNull String input) { return Hashing.murmur3_32(MURMUR_SEED).hashString(input, Charsets.UTF_8).asInt(); }
From source file:net.xby1993.common.util.io.HashUtil.java
/** * murmur128, ?/*from w ww . j a va2 s .com*/ */ public static long murmur128AsLong(@NotNull String input) { return Hashing.murmur3_128(MURMUR_SEED).hashString(input, Charsets.UTF_8).asLong(); }
From source file:ninja.benchmark.NinjaBenchmark.java
public Request buildPostObjectAsJsonRequest() { byte[] json = "{ \"s\":\"sam\", \"i\":2, \"l\":10000000, \"b\":true }".getBytes(Charsets.UTF_8); return new Request.Builder().url(standalone.getBaseUrls().get(0) + "/benchmark_object?a=adam&b=bob") .header("Cookie", "TEST=THISISATESTCOOKIEHEADER") .post(RequestBody.create(MediaType.parse("application/json"), json)).build(); }
From source file:ninja.undertow.Benchmarker.java
static public void main(String[] args) throws Exception { // spin up standalone, but don't join Standalone standalone = new NinjaUndertow() //Standalone standalone = new NinjaJetty() .externalConfigurationPath("conf/undertow.example.conf") .port(StandaloneHelper.findAvailablePort(8000, 9000)).start(); final int requests = 100000; final int threads = 50; final OkHttpClient client = NinjaOkHttp3Tester.newHttpClientBuilder() .connectionPool(new ConnectionPool(threads, 60000L, TimeUnit.MILLISECONDS)).build(); final AtomicInteger requested = new AtomicInteger(); /**// w ww.j av a2 s . c om // get request w/ parameters final Request request = requestBuilder(standalone, "/parameters?a=joe&c=cat&d=dog&e=egg&f=frank&g=go") .header("Cookie", "TEST=THISISATESTCOOKIEHEADER") .build(); */ // json request w/ parameters byte[] json = "{ \"s\":\"string\", \"i\":2 }".getBytes(Charsets.UTF_8); final Request request = requestBuilder(standalone, "/benchmark_json?a=joe&c=cat&d=dog&e=egg&f=frank&g=go") .header("Cookie", "TEST=THISISATESTCOOKIEHEADER") .post(RequestBody.create(MediaType.parse("application/json"), json)).build(); /** final Request request = requestBuilder(standalone, "/benchmark_form?a=joe&c=cat&d=dog&e=egg&f=frank&g=go") .post(new FormBody.Builder() .add("a", "frank") .add("b", "2") .add("h", "hello") .add("z", "zulu") .build()) .build(); */ // warmup for (int i = 0; i < 100; i++) { Response response = executeRequest(client, request); response.body().close(); } final CountDownLatch startSignal = new CountDownLatch(1); final CountDownLatch doneSignal = new CountDownLatch(threads); ExecutorService threadPool = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { threadPool.submit(new Runnable() { @Override public void run() { try { startSignal.await(); while (requested.incrementAndGet() < requests) { Response response = executeRequest(client, request); response.body().close(); } doneSignal.countDown(); } catch (InterruptedException | IOException e) { log.error("", e); } } }); } // real Stopwatch stopwatch = Stopwatch.createStarted(); startSignal.countDown(); doneSignal.await(); stopwatch.stop(); log.info("Took {} ms for {} requests", stopwatch.elapsed(TimeUnit.MILLISECONDS), requests); logMemory(); standalone.shutdown(); threadPool.shutdown(); }
From source file:ninja.vertx.Benchmarker.java
static public void main(String[] args) throws Exception { // spin up standalone, but don't join Standalone standalone = new NinjaVertx() // Standalone standalone = new NinjaJetty() .externalConfigurationPath("conf/vertx.example.conf") .port(StandaloneHelper.findAvailablePort(8000, 9000)).start(); final int requests = 100000; final int threads = 1000; final OkHttpClient client = NinjaOkHttp3Tester.newHttpClientBuilder() .connectionPool(new ConnectionPool(threads, 60000L, TimeUnit.MILLISECONDS)).build(); final AtomicInteger requested = new AtomicInteger(); /**//from ww w . j a v a2 s . co m // get request w/ parameters final Request request = requestBuilder(standalone, "/parameters?a=joe&c=cat&d=dog&e=egg&f=frank&g=go") .header("Cookie", "TEST=THISISATESTCOOKIEHEADER") .build(); */ // json request w/ parameters byte[] json = "{ \"s\":\"string\", \"i\":2 }".getBytes(Charsets.UTF_8); final Request request = requestBuilder(standalone, "/benchmark_json?a=joe&c=cat&d=dog&e=egg&f=frank&g=go") .header("Cookie", "TEST=THISISATESTCOOKIEHEADER") .post(RequestBody.create(MediaType.parse("application/json"), json)).build(); /** final Request request = requestBuilder(standalone, "/benchmark_form?a=joe&c=cat&d=dog&e=egg&f=frank&g=go") .post(new FormBody.Builder() .add("a", "frank") .add("b", "2") .add("h", "hello") .add("z", "zulu") .build()) .build(); */ // warmup for (int i = 0; i < 100; i++) { Response response = executeRequest(client, request); response.body().close(); } final CountDownLatch startSignal = new CountDownLatch(1); final CountDownLatch doneSignal = new CountDownLatch(threads); ExecutorService threadPool = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { threadPool.submit(new Runnable() { @Override public void run() { try { startSignal.await(); while (requested.incrementAndGet() < requests) { Response response = executeRequest(client, request); response.body().close(); } doneSignal.countDown(); } catch (InterruptedException | IOException e) { log.error("", e); } } }); } // real Stopwatch stopwatch = Stopwatch.createStarted(); startSignal.countDown(); doneSignal.await(); stopwatch.stop(); log.info("Took {} ms for {} requests", stopwatch.elapsed(TimeUnit.MILLISECONDS), requests); logMemory(); standalone.shutdown(); threadPool.shutdown(); }
From source file:nl.knaw.huygens.alexandria.endpoint.resource.ResourceTextEndpoint.java
@PUT @Consumes(MediaType.APPLICATION_OCTET_STREAM) @ApiOperation("set text from stream") public Response setTextFromXmlStream(InputStream inputStream) { try {//from w w w . ja v a 2 s.c o m String xml = IOUtils.toString(inputStream, Charsets.UTF_8); return setTextFromXml(xml); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:org.ambraproject.wombat.config.SpringSecurityConfiguration.java
private LogoutSuccessHandler getLogoutSuccessHandler() { return runtimeConfiguration.getCasConfiguration() .map(casConfiguration -> (LogoutSuccessHandler) (HttpServletRequest request, HttpServletResponse response, Authentication authentication) -> { if (authentication != null && authentication.getDetails() != null) { try { request.getSession().invalidate(); } catch (IllegalStateException e) { // session is already invalid, so nothing to do, but log as error since it may indicate a config issue log.error("Attempted to log out of an already logged out session"); }/*from www . jav a2s. c o m*/ } validateHostname(request); String logoutServiceUrl = Link.toSitelessHandler() .toPattern(requestMappingContextDictionary, LOGOUT_HANDLER_NAME).build().get(request); response.setStatus(HttpServletResponse.SC_OK); response.sendRedirect(casConfiguration.getLogoutUrl() + "?service=" + URLEncoder.encode(logoutServiceUrl, Charsets.UTF_8.name())); }).orElseThrow(CasConfigurationRequiredException::new); }
From source file:org.ambraproject.wombat.service.remote.ApiAddress.java
private static String encodePath(String path) { try {//from w ww . ja va 2s. c o m return URLEncoder.encode(path, Charsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }