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:cloudfoundry.norouter.f5.F5Initializer.java

ST routerIRule() throws IOException {
    final ClassPathResource resource = new ClassPathResource("templates/irules/router.tcl.st");
    final String template = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8);
    return new ST(template, '`', '`');
}

From source file:gobblin.converter.avro.BytesToAvroConverterTest.java

@Test
public void testCanParseBinary() throws DataConversionException, SchemaConversionException, IOException {
    InputStream schemaIn = getClass().getClassLoader()
            .getResourceAsStream(RESOURCE_PATH_PREFIX + "test_record_schema.avsc");
    InputStream recordIn = getClass().getClassLoader()
            .getResourceAsStream(RESOURCE_PATH_PREFIX + "test_record_binary.avro");
    Assert.assertNotNull("Could not load test schema from resources", schemaIn);
    Assert.assertNotNull("Could not load test record from resources", recordIn);

    BytesToAvroConverter converter = new BytesToAvroConverter();
    WorkUnitState state = new WorkUnitState();

    converter.init(state);//from ww  w.  j  a  va  2 s .  co  m
    Schema schema = converter.convertSchema(IOUtils.toString(schemaIn, StandardCharsets.UTF_8), state);

    Assert.assertEquals(schema.getName(), "testRecord");

    Iterator<GenericRecord> records = converter.convertRecord(schema, IOUtils.toByteArray(recordIn), state)
            .iterator();
    GenericRecord record = records.next();

    Assert.assertFalse("Expected only 1 record", records.hasNext());

    Assert.assertEquals(record.get("testStr").toString(), "testing123");
    Assert.assertEquals(record.get("testInt"), -2);
}

From source file:io.github.swagger2markup.internal.component.LicenseInfoComponentTest.java

@Test
public void testLicenseInfoComponent() throws URISyntaxException {

    Info info = new Info()
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))
            .termsOfService("Bla bla bla");

    Swagger2MarkupConverter.Context context = createContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    markupDocBuilder = new LicenseInfoComponent(context).apply(markupDocBuilder,
            LicenseInfoComponent.parameters(info, OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

}

From source file:com.google.jenkins.plugins.credentials.oauth.KeyUtils.java

/**
 * Writes the given key to the given keyfile, passing it through
 * {@link Secret} to encode the string. Note that, per the documentation of
 * {@link Secret}, this does not protect against an attacker who has full
 * access to the local file system, but reduces the chance of accidental
 * exposure./*from www. j  a  v a2 s .  c  o  m*/
 */
public static void writeKeyToFileEncoded(String key, File file) throws IOException {
    if (key == null || file == null) {
        return;
    }
    Secret encoded = Secret.fromString(key);
    writeKeyToFile(IOUtils.toInputStream(encoded.getEncryptedValue(), StandardCharsets.UTF_8), file);
}

From source file:com.intbit.util.ServletUtil.java

public static String getServerName(ServletContext context) {
    try {//from   w w  w  . jav a2s.c om
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        String path = context.getRealPath("") + "/js/configurations.js";
        // read script file
        engine.eval(Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8));

        Invocable inv = (Invocable) engine;
        // call function from script file
        return inv.invokeFunction("getHost", "").toString();
    } catch (Exception ex) {
        return "http://clients.brndbot.com/BrndBot/";
    }
}

From source file:com.lexicalintelligence.admin.add.AddRequest.java

public AddResponse execute() {
    List<BasicNameValuePair> params = Collections
            .singletonList(new BasicNameValuePair(getName(), StringUtils.join(items, ",")));
    AddResponse addResponse;/*from  w w  w .j  a va2  s  .  c  om*/
    Reader reader = null;
    try {
        HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath()
                + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8)));
        reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8);
        addResponse = new AddResponse(Boolean.valueOf(IOUtils.toString(reader)));
    } catch (Exception e) {
        addResponse = new AddResponse(false);
        log.error(e);
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
            log.error(e);
        }
    }
    return addResponse;
}

From source file:com.lexicalintelligence.admin.remove.RemoveEntryRequest.java

@Override
public RemoveResponse execute() {
    RemoveResponse removeResponse;/*www.  j av  a2  s. c  om*/

    List<BasicNameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("name", entry.getName()));
    params.add(new BasicNameValuePair("synonym", entry.getSynonym()));

    Reader reader = null;
    try {
        HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath()
                + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8)));
        reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8);
        removeResponse = new RemoveResponse(Boolean.valueOf(IOUtils.toString(reader)));
    } catch (Exception e) {
        removeResponse = new RemoveResponse(false);
        log.error(e);
    } finally {
        try {
            reader.close();
        } catch (Exception e) {

        }
    }
    return removeResponse;
}

From source file:com.github.benmanes.caffeine.cache.simulator.parser.wikipedia.WikipediaTraceReader.java

@Override
public LongStream events() throws IOException {
    return lines().map(this::parseRequest).filter(Objects::nonNull)
            .mapToLong(path -> Hashing.murmur3_128().hashString(path, StandardCharsets.UTF_8).asLong());
}

From source file:cn.edu.zjnu.acm.judge.security.password.MessageDigestPasswordEncoder.java

@Override
public String encode(CharSequence password) {
    MessageDigest digest = getMessageDigest(algorithm);
    return new String(Hex.encode(digest
            .digest(password != null ? password.toString().getBytes(StandardCharsets.UTF_8) : new byte[0])));
}

From source file:com.blackducksoftware.integration.hub.detect.detector.npm.NpmLockfileExtractor.java

public Extraction extract(final File directory, final File lockfile, final Optional<File> packageJson) {
    try {//from w w  w  . j  a  v a 2s . c o  m
        final boolean includeDev = detectConfiguration
                .getBooleanProperty(DetectProperty.DETECT_NPM_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None);

        String lockText = FileUtils.readFileToString(lockfile, StandardCharsets.UTF_8);
        Optional<String> packageText = Optional.empty();
        if (packageJson.isPresent()) {
            packageText = Optional.of(FileUtils.readFileToString(packageJson.get(), StandardCharsets.UTF_8));
        }

        final NpmParseResult result = npmLockfileParser.parse(directory.getCanonicalPath(), packageText,
                lockText, includeDev);

        return new Extraction.Builder().success(result.codeLocation).projectName(result.projectName)
                .projectVersion(result.projectVersion).build();

    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
}