Example usage for java.nio.charset StandardCharsets UTF_8

List of usage examples for java.nio.charset StandardCharsets UTF_8

Introduction

In this page you can find the example usage for java.nio.charset StandardCharsets UTF_8.

Prototype

Charset UTF_8

To view the source code for java.nio.charset StandardCharsets UTF_8.

Click Source Link

Document

Eight-bit UCS Transformation Format.

Usage

From source file:org.maodian.flyingcat.xmpp.XmppServerInitializer.java

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();/* w w  w .  j av a2 s  . c  o  m*/

    String delimiter = ">";// XmppMessageInboundHandler.STREAM_NAME + ">";
    p.addLast("Frame", new DelimiterBasedFrameDecoder(8192, false, true,
            Unpooled.wrappedBuffer(delimiter.getBytes(StandardCharsets.UTF_8))));
    p.addLast("Logger", DECODER);
    p.addLast("XmlFragment", new XMLFragmentDecoder());
    p.addLast("Encoder", ENCODER);
    // p.addLast("Echo", new XmppMessageInboundHandler());
    // p.addLast("Echo", new StreamNegotiationHandler());
    XmppXMLStreamHandler streamHandler = beanFactory.getBean(XmppXMLStreamHandler.class);
    p.addLast("Echo", streamHandler);
}

From source file:org.zalando.logbook.httpclient.Response.java

@Override
public Charset getCharset() {
    return Optional.of(response).map(request -> request.getFirstHeader("Content-Type")).map(Header::getValue)
            .map(ContentType::parse).map(ContentType::getCharset).orElse(StandardCharsets.UTF_8);
}

From source file:com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager.java

public NugetParseResult createDetectCodeLocation(final File dependencyNodeFile) throws IOException {
    final String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
    final NugetInspection nugetInspection = gson.fromJson(text, NugetInspection.class);

    final List<DetectCodeLocation> codeLocations = new ArrayList<>();
    String projectName = "";
    String projectVersion = "";
    for (final NugetContainer it : nugetInspection.containers) {
        final Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it);
        if (possibleParseResult.isPresent()) {
            final NugetParseResult result = possibleParseResult.get();
            if (StringUtils.isNotBlank(result.projectName)) {
                projectName = result.projectName;
                projectVersion = result.projectVersion;
            }/*from  w w w.java  2s .c o  m*/
            codeLocations.addAll(result.codeLocations);
        }
    }

    return new NugetParseResult(projectName, projectVersion, codeLocations);
}

From source file:com.twosigma.beaker.core.rest.RecentMenuRest.java

@Inject
public RecentMenuRest(BeakerConfig bkConfig, GeneralUtils utils) {
    this.utils = utils;
    this.recentDocumentsFile = Paths.get(bkConfig.getRecentNotebooksFileUrl());
    this.recentDocuments = new LinkedBlockingDeque<>();

    // read from file -> recentDocuments
    List<String> lines = new ArrayList<>();
    if (Files.exists(recentDocumentsFile)) {
        try {//from   ww w. j  ava 2 s .com
            lines = Files.readAllLines(recentDocumentsFile, StandardCharsets.UTF_8);
        } catch (IOException ex) {
            logger.warn("Failed to get recent documents", ex);
        }
    }
    for (String line : lines) {
        addRecentDocument(line.trim());
    }
}

From source file:cz.muni.fi.mir.mathmlunificator.AbstractXMLTransformationTest.java

protected InputStream getTestResource(String testFile) {
    String resourceFile = this.getClass().getSimpleName() + "/" + testFile;
    InputStream rs = this.getClass().getResourceAsStream(resourceFile);
    return new ReaderInputStream(new InputStreamReader(rs, StandardCharsets.UTF_8), StandardCharsets.UTF_8);
}

From source file:com.linecorp.bot.servlet.LineBotCallbackRequestParser.java

/**
 * Parse request./*from w w  w  . ja  v a2 s.  c o  m*/
 *
 * @param req HTTP servlet request.
 * @return Parsed result. If there's an error, this method sends response.
 * @throws LineBotCallbackException There's an error around signature.
 */
public CallbackRequest handle(HttpServletRequest req) throws LineBotCallbackException, IOException {
    // validate signature
    String signature = req.getHeader("X-Line-Signature");
    if (signature == null || signature.length() == 0) {
        throw new LineBotCallbackException("Missing 'X-Line-Signature' header");
    }

    final byte[] json = ByteStreams.toByteArray(req.getInputStream());
    if (log.isDebugEnabled()) {
        log.debug("got: {}", new String(json, StandardCharsets.UTF_8));
    }

    if (!lineSignatureValidator.validateSignature(json, signature)) {
        throw new LineBotCallbackException("Invalid API signature");
    }

    final CallbackRequest callbackRequest = objectMapper.readValue(json, CallbackRequest.class);
    if (callbackRequest == null || callbackRequest.getEvents() == null) {
        throw new LineBotCallbackException("Invalid content");
    }
    return callbackRequest;
}

From source file:kmi.taa.core.SPARQLHTTPClient.java

public String httpGet(String url, String proxy) throws ClientProtocolException, IOException {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(url);
    String responseBody;/*  www.  j av  a 2s  . c  o m*/
    try {
        if (!proxy.isEmpty()) {
            String[] str = proxy.split(":");
            int port = Integer.parseInt(str[1]);
            HttpHost host = new HttpHost(str[0], port, str[2]);
            RequestConfig config = RequestConfig.custom().setProxy(host).build();
            httpget.setConfig(config);
        }

        ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
            public String handleResponse(final HttpResponse response)
                    throws ClientProtocolException, IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= 200 && status < 300) {
                    try {
                        HttpEntity entity = response.getEntity();
                        return entity != null ? EntityUtils.toString(entity, StandardCharsets.UTF_8) : null;
                    } catch (ClientProtocolException e) {
                        return "";
                    }
                }
                return "";
            }

        };

        responseBody = httpclient.execute(httpget, responseHandler);
    } finally {
        httpclient.close();
    }

    return responseBody;
}

From source file:com.thoughtworks.go.websocket.MessageEncoding.java

public static Message decodeMessage(InputStream input) {
    try {//  ww  w.j a v  a2  s  .  c  om
        try (GZIPInputStream zipStream = new GZIPInputStream(input)) {
            String jsonStr = new String(IOUtils.toByteArray(zipStream), StandardCharsets.UTF_8);
            return gson.fromJson(jsonStr, Message.class);
        }
    } catch (IOException e) {
        throw bomb(e);
    }
}

From source file:cd.go.contrib.elasticagents.docker.DockerClientFactory.java

private static void setupCerts(PluginSettings pluginSettings, DefaultDockerClient.Builder builder)
        throws IOException, DockerCertificateException {
    if (isBlank(pluginSettings.getDockerCACert()) || isBlank(pluginSettings.getDockerClientCert())
            || isBlank(pluginSettings.getDockerClientKey())) {
        LOG.warn("Missing docker certificates, will attempt to connect without certificates");
        return;/* w  ww .  ja  v  a2 s.c  om*/
    }

    Path certificateDir = Files.createTempDirectory(UUID.randomUUID().toString());
    File tempDirectory = certificateDir.toFile();

    try {
        FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CA_CERT_NAME),
                pluginSettings.getDockerCACert(), StandardCharsets.UTF_8);
        FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CLIENT_CERT_NAME),
                pluginSettings.getDockerClientCert(), StandardCharsets.UTF_8);
        FileUtils.writeStringToFile(new File(tempDirectory, DockerCertificates.DEFAULT_CLIENT_KEY_NAME),
                pluginSettings.getDockerClientKey(), StandardCharsets.UTF_8);
        builder.dockerCertificates(new DockerCertificates(certificateDir));
    } finally {
        FileUtils.deleteDirectory(tempDirectory);
    }
}