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:org.dspace.sword2.SwordUrlManager.java
public String getActionableBitstreamUrl(Bitstream bitstream) throws DSpaceSwordException { try {//from w w w . j a v a 2 s.c o m return this.getSwordBaseUrl() + "/edit-media/bitstream/" + bitstream.getID() + "/" + URLEncoder.encode(bitstream.getName(), Charsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { return this.getSwordBaseUrl() + "/edit-media/bitstream/" + bitstream.getID() + "/" + bitstream.getName(); } }
From source file:org.duracloud.common.web.RestHttpHelper.java
private InputStreamEntity buildInputStreamEntity(String requestContent, String mimeType) throws Exception { if (requestContent == null) { return null; }//from ww w . j a v a 2 s .com InputStream streamContent = IOUtil.writeStringToStream(requestContent); return buildInputStreamEntity(streamContent, mimeType, requestContent.getBytes(Charsets.UTF_8).length); }
From source file:org.echocat.marquardt.authority.AuthorityIntegrationTest.java
private void doPost(final String url, final Object content) throws Exception { final byte[] bytes; try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { _objectMapper.writeValue(byteArrayOutputStream, content); byteArrayOutputStream.flush();/* w w w .ja va 2 s. c o m*/ bytes = byteArrayOutputStream.toByteArray(); } final URI urlToPost = new URI(url); final ClientHttpRequest request = new OkHttpClientHttpRequestFactory().createRequest(urlToPost, HttpMethod.POST); request.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); request.getHeaders().add(X_CERTIFICATE.getHeaderName(), Base64.encodeBase64URLSafeString(CERTIFICATE)); request.getBody().write(bytes); final ClientHttpResponse response = request.execute(); _status = response.getStatusCode().value(); try (final InputStream inputStream = response.getBody()) { try (final InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charsets.UTF_8)) { _response = CharStreams.toString(inputStreamReader); } } }
From source file:org.eclipse.leshan.bootstrap.BootstrapSecurityStore.java
@Override public SecurityInfo getByIdentity(String identity) { byte[] identityBytes = identity.getBytes(Charsets.UTF_8); for (Map.Entry<String, BootstrapConfig> e : bsStore.getBootstrapConfigs().entrySet()) { for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> ec : e.getValue().security.entrySet()) { if (ec.getValue().bootstrapServer && ec.getValue().securityMode == SecurityMode.PSK && Arrays.equals(ec.getValue().publicKeyOrId, identityBytes)) { return SecurityInfo.newPreSharedKeyInfo(e.getKey(), identity, ec.getValue().secretKey); }/*from www . j a v a 2 s. com*/ } } return null; }
From source file:org.eclipse.leshan.bootstrap.BootstrapSecurityStore.java
@Override public SecurityInfo getByEndpoint(String endpoint) { BootstrapConfig bootstrap = bsStore.getBootstrap(endpoint); for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> e : bootstrap.security.entrySet()) { ServerSecurity value = e.getValue(); if (value.bootstrapServer && value.securityMode == SecurityMode.PSK) { // got it! return SecurityInfo.newPreSharedKeyInfo(endpoint, new String(value.publicKeyOrId, Charsets.UTF_8), value.secretKey);/*from ww w .j ava2 s. co m*/ } } return null; }
From source file:org.eclipse.leshan.bootstrap.servlet.BootstrapServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getPathInfo() != null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return;/* w ww . java2s. co m*/ } resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); resp.getOutputStream().write(gson.toJson(bsStore.getBootstrapConfigs()).getBytes(Charsets.UTF_8)); }
From source file:org.eclipse.leshan.server.bootstrap.demo.BootstrapSecurityStoreImpl.java
@Override public SecurityInfo getByIdentity(String identity) { byte[] identityBytes = identity.getBytes(Charsets.UTF_8); for (Map.Entry<String, BootstrapConfig> e : bsStore.getBootstrapConfigs().entrySet()) { BootstrapConfig bsConfig = e.getValue(); if (bsConfig.security != null) { for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> ec : bsConfig.security.entrySet()) { ServerSecurity serverSecurity = ec.getValue(); if (serverSecurity.bootstrapServer && serverSecurity.securityMode == SecurityMode.PSK && Arrays.equals(serverSecurity.publicKeyOrId, identityBytes)) { return SecurityInfo.newPreSharedKeyInfo(e.getKey(), identity, serverSecurity.secretKey); }/*from w w w. j a v a 2 s . co m*/ } } } return null; }
From source file:org.eclipse.leshan.server.bootstrap.demo.BootstrapSecurityStoreImpl.java
@Override public List<SecurityInfo> getAllByEndpoint(String endpoint) { BootstrapConfig bsConfig = bsStore.getBootstrap(endpoint); if (bsConfig == null || bsConfig.security == null) return null; for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> e : bsConfig.security.entrySet()) { ServerSecurity value = e.getValue(); if (value.bootstrapServer && value.securityMode == SecurityMode.PSK) { // got it! SecurityInfo securityInfo = SecurityInfo.newPreSharedKeyInfo(endpoint, new String(value.publicKeyOrId, Charsets.UTF_8), value.secretKey); return Arrays.asList(securityInfo); }//from w w w .j a v a 2 s .c om } return null; }
From source file:org.eclipse.leshan.server.demo.servlet.log.CoapMessage.java
private CoapMessage(boolean incoming, Type type, int mId, String token, OptionSet options, byte[] payload) { this.incoming = incoming; this.timestamp = System.currentTimeMillis(); this.type = type.toString(); this.mId = mId; this.token = token; if (options != null) { List<Option> opts = options.asSortedList(); if (!opts.isEmpty()) { Map<String, List<String>> optMap = new HashMap<>(); for (Option opt : opts) { String strOption = OptionNumberRegistry.toString(opt.getNumber()); List<String> values = optMap.get(strOption); if (values == null) { values = new ArrayList<>(); optMap.put(strOption, values); }//from w w w .ja va2s . com values.add(opt.toValueString()); } StringBuilder builder = new StringBuilder(); for (Entry<String, List<String>> e : optMap.entrySet()) { if (builder.length() > 0) { builder.append(" - "); } builder.append(e.getKey()).append(": ").append(StringUtils.join(e.getValue(), ", ")); } this.options = builder.toString(); } } if (payload != null && payload.length > 0) { String strPayload = new String(payload, Charsets.UTF_8); if (StringUtils.isAsciiPrintable(strPayload)) { this.payload = strPayload; } else { this.payload = "Hex:" + Hex.encodeHexString(payload); } } }
From source file:org.eclipse.leshan.standalone.servlet.log.CoapMessage.java
private CoapMessage(boolean incoming, Type type, int mId, String token, OptionSet options, byte[] payload) { this.incoming = incoming; this.timestamp = System.currentTimeMillis(); this.type = type.toString(); this.mId = mId; this.token = token; if (options != null) { List<Option> opts = options.asSortedList(); if (!opts.isEmpty()) { Map<String, List<String>> optMap = new HashMap<>(); for (Option opt : opts) { String strOption = OptionNumberRegistry.toString(opt.getNumber()); List<String> values = optMap.get(strOption); if (values == null) { values = new ArrayList<>(); optMap.put(strOption, values); }/*from ww w . j a va2s .co m*/ switch (opt.getNumber()) { case OptionNumberRegistry.CONTENT_FORMAT: values.add(String.valueOf(opt.getIntegerValue())); break; default: values.add(opt.getStringValue()); } } StringBuilder builder = new StringBuilder(); for (Entry<String, List<String>> e : optMap.entrySet()) { if (builder.length() > 0) { builder.append(" - "); } builder.append(e.getKey()).append(": ").append(StringUtils.join(e.getValue(), ", ")); } this.options = builder.toString(); } } if (payload != null && payload.length > 0) { String strPayload = new String(payload, Charsets.UTF_8); if (StringUtils.isAsciiPrintable(strPayload)) { this.payload = strPayload; } else { this.payload = "Hex:" + Hex.encodeHexString(payload); } } }