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:hrytsenko.gscripts.App.java

private static void executeEmbeddedScript(GroovyShell shell, String scriptName) {
    try {/*from   w  w w .j  a  va  2  s  .c om*/
        shell.evaluate(Resources.toString(Resources.getResource(scriptName), StandardCharsets.UTF_8));
    } catch (IOException exception) {
        throw new AppException(String.format("Cannot execute embedded script %s.", scriptName), exception);
    }
}

From source file:com.bombardier.plugin.utils.FilePathUtils.java

/**
 * Used to read test cases from a list - line by line.
 * //from   ww  w. j av a2 s.  co m
 * @param file
 *            the {@link Path} to the file
 * @return An {@link List} containing all test cases.
 * @throws IOException
 * @since 1.0
 */
public static List<String> readTextFileByLines(FilePath file) throws Exception {
    List<String> list = Files.readAllLines(Paths.get(file.absolutize().toURI()), StandardCharsets.UTF_8);
    list.removeIf(new Predicate<String>() {
        @Override
        public boolean test(String arg0) {
            return !StringUtils.isNotBlank(arg0);
        }
    });
    return list;
}

From source file:eu.smartfp7.foursquare.utils.Settings.java

protected Settings() {
    // We load the settings file and parse its JSON only once.
    try {//from ww w.  ja  va  2s .c o m
        JsonParser parser = new JsonParser();
        this.settings_json = parser
                .parse(StringUtils
                        .join(Files.readAllLines(Paths.get("etc/settings.json"), StandardCharsets.UTF_8), " "))
                .getAsJsonObject();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.xwiki.velocity.tools.URLTool.java

/**
 * Parse a query string into a map of key-value pairs.
 * //from www  .  ja  v a2  s .  co  m
 * @param query query string to be parsed
 * @return a mapping of parameter names to values suitable e.g. to pass into {@link EscapeTool#url(Map)}
 */
public Map<String, List<String>> parseQuery(String query) {
    Map<String, List<String>> queryParams = new LinkedHashMap<>();
    if (query != null) {
        for (NameValuePair params : URLEncodedUtils.parse(query, StandardCharsets.UTF_8)) {
            String name = params.getName();
            List<String> values = queryParams.get(name);
            if (values == null) {
                values = new ArrayList<>();
                queryParams.put(name, values);
            }
            values.add(params.getValue());
        }
    }
    return queryParams;
}

From source file:org.xwiki.test.escaping.framework.URLContent.java

public Reader getContentReader() {
    Charset charset;// ww w .  ja  v  a2  s  .  c o m
    if (this.type != null && this.type.getCharset() != null) {
        charset = this.type.getCharset();
    } else {
        charset = StandardCharsets.UTF_8;
    }

    return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(getContent()), charset));
}

From source file:com.shareplaylearn.resources.test.AccessTokenTest.java

public OauthPasswordFlow.LoginInfo testPost() throws IOException {
    HttpPost httpPost = new HttpPost(ACCESS_TOKEN_RESOURCE);
    String credentialsString = username + ":" + password;
    httpPost.addHeader("Authorization",
            Base64.encodeBase64String(credentialsString.getBytes(StandardCharsets.UTF_8)));

    try (CloseableHttpResponse response = BackendTest.httpClient.execute(httpPost)) {
        BackendTest.ProcessedHttpResponse processedHttpResponse = new BackendTest.ProcessedHttpResponse(
                response);/*from  w  w w  .ja  va 2 s.  c o  m*/
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException(
                    "Error testing access token endpoint: " + processedHttpResponse.completeMessage);
        }
        return new Gson().fromJson(processedHttpResponse.entity, OauthPasswordFlow.LoginInfo.class);
    }
}

From source file:com.spectralogic.ds3client.commands.spectrads3.GetBlobPersistenceSpectraS3Response.java

@Override
protected void processResponse() throws IOException {
    try {/*w ww  .  j a  v  a2  s . co m*/
        this.checkStatusCode(200);

        switch (this.getStatusCode()) {
        case 200:
            try (final InputStream content = getResponse().getResponseStream()) {
                this.stringResult = IOUtils.toString(content, StandardCharsets.UTF_8);
            }
            break;
        default:
            assert false : "checkStatusCode should have made it impossible to reach this line.";
        }
    } finally {
        this.getResponse().close();
    }
}

From source file:com.toptal.conf.SecurityUtils.java

/**
 * Decodes given string from base64.//from w w  w .  j  a  va2  s  .co  m
 * @param str String.
 * @return Decoded string.
 */
public static String decode(final String str) {
    String result = null;
    if (str != null) {
        result = new String(Base64.getDecoder().decode(str), StandardCharsets.UTF_8);
    }
    return result;
}

From source file:com.linecorp.armeria.server.docs.FunctionInfo.java

static FunctionInfo of(Method method, Map<Class<?>, ? extends TBase<?, ?>> sampleRequests,
        @Nullable String namespace, Map<String, String> docStrings) throws ClassNotFoundException {
    requireNonNull(method, "method");

    final String methodName = method.getName();

    final Class<?> serviceClass = method.getDeclaringClass().getDeclaringClass();
    final String serviceName = serviceClass.getName();
    final ClassLoader classLoader = serviceClass.getClassLoader();

    @SuppressWarnings("unchecked")
    Class<? extends TBase<?, ?>> argsClass = (Class<? extends TBase<?, ?>>) Class
            .forName(serviceName + '$' + methodName + "_args", false, classLoader);
    String sampleJsonRequest;//w  ww .  ja  v a2s  .  c  o  m
    TBase<?, ?> sampleRequest = sampleRequests.get(argsClass);
    if (sampleRequest == null) {
        sampleJsonRequest = "";
    } else {
        TSerializer serializer = new TSerializer(ThriftProtocolFactories.TEXT);
        try {
            sampleJsonRequest = serializer.toString(sampleRequest, StandardCharsets.UTF_8.name());
        } catch (TException e) {
            throw new IllegalArgumentException(
                    "Failed to serialize to a memory buffer, this shouldn't ever happen.", e);
        }
    }

    @SuppressWarnings("unchecked")
    final FunctionInfo function = new FunctionInfo(namespace, methodName, argsClass,
            (Class<? extends TBase<?, ?>>) Class.forName(serviceName + '$' + methodName + "_result", false,
                    classLoader),
            (Class<? extends TException>[]) method.getExceptionTypes(), sampleJsonRequest, docStrings);
    return function;
}

From source file:io.wcm.devops.conga.plugins.sling.fileheader.OsgiConfigFileHeaderTest.java

@Test
public void testApply() throws Exception {
    File file = new File("target/generation-test/fileHeader.config");
    FileUtils.write(file, "myscript", StandardCharsets.UTF_8);

    List<String> lines = ImmutableList.of("**********", "", "Der Jodelkaiser", "aus dem Oetztal",
            "ist wieder daheim.", "**********");
    FileHeaderContext context = new FileHeaderContext().commentLines(lines);

    FileContext fileContext = new FileContext().file(file);
    assertTrue(underTest.accepts(fileContext, context));
    underTest.apply(fileContext, context);

    assertTrue(StringUtils.contains(FileUtils.readFileToString(file, StandardCharsets.UTF_8),
            "# Der Jodelkaiser aus dem Oetztal ist wieder daheim."));

    FileHeaderContext extractContext = underTest.extract(fileContext);
    assertEquals(ImmutableList.of("Der Jodelkaiser aus dem Oetztal ist wieder daheim."),
            extractContext.getCommentLines());

    file.delete();/*from  ww  w.j  a  va  2 s . c o  m*/
}