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:com.twosigma.beakerx.kernel.magic.command.PomFactory.java

public String createPom(Params params) throws IOException {
    InputStream pom = getClass().getClassLoader().getResourceAsStream(MavenJarResolver.POM_XML);
    String pomAsString = IOUtils.toString(pom, StandardCharsets.UTF_8);
    pomAsString = configureOutputDir(params.pathToMavenRepo, pomAsString);
    pomAsString = configureDependencies(params.dependencies, pomAsString);
    pomAsString = configureRepos(params.repos, pomAsString);
    pomAsString = configureGoal(params.goal, pomAsString);
    pomAsString = configureBuildClasspathPlugin(params.pathToMavenRepo, params.mavenBuiltClasspathFileName,
            pomAsString);//from  www  .j a v  a 2 s  . co  m
    return pomAsString;
}

From source file:net.sf.jabref.importer.fetcher.BibsonomyScraper.java

/**
 * Return a BibEntry by looking up the given url from the BibSonomy scraper.
 * @param entryUrl// w  w  w  .  j  av  a  2 s .  c o  m
 * @return
 */
public static Optional<BibEntry> getEntry(String entryUrl) {
    try {
        // Replace special characters by corresponding sequences:
        String cleanURL = entryUrl.replace("%", "%25").replace(":", "%3A").replace("/", "%2F")
                .replace("?", "%3F").replace("&", "%26").replace("=", "%3D");

        URL url = new URL(
                BibsonomyScraper.BIBSONOMY_SCRAPER + cleanURL + BibsonomyScraper.BIBSONOMY_SCRAPER_POST);
        String bibtex = new URLDownload(url).downloadToString(StandardCharsets.UTF_8);
        BibtexParser bp = new BibtexParser(new StringReader(bibtex));
        ParserResult pr = bp.parse();
        if ((pr != null) && pr.getDatabase().hasEntries()) {
            return Optional.of(pr.getDatabase().getEntries().iterator().next());
        } else {
            return Optional.empty();
        }

    } catch (IOException ex) {
        LOGGER.warn("Could not download entry", ex);
        return Optional.empty();
    } catch (RuntimeException ex) {
        LOGGER.warn("Could not get entry", ex);
        return Optional.empty();
    }
}

From source file:spring.travel.site.auth.Signer.java

public String sign(String data) throws AuthException {
    try {/*from   ww w  . j  av  a 2 s .c  om*/
        SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), HMAC_SHA1_ALGORITHM);
        Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
        mac.init(signingKey);
        byte[] raw = mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
        return toHex(raw);
    } catch (InvalidKeyException | NoSuchAlgorithmException e) {
        throw new AuthException("Failed signing data", e);
    }
}

From source file:com.google.api.ads.adwords.awreporting.server.appengine.processors.TaskHtml2PdfOverNet.java

@Test
public void test_run() throws IOException {

    String html = "<html>HOLA</html>";

    InputStream htmlSource = new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8));

    MemoryReportWriter mrwHtml = MemoryReportWriter.newMemoryReportWriter();

    ReportExporterAppEngine.html2PdfOverNet(htmlSource, mrwHtml);

    IOUtils.toString(mrwHtml.getAsSource(), "UTF-8");

}

From source file:actuatorapp.ActuatorApp.java

public ActuatorApp() throws IOException, JSONException {
    //Takes a sting with a relay name "RELAYLO1-10FAD.relay1"
    //Actuator a = new Actuator("RELAYLO1-12854.relay1");    
    //Starts the virtualhub that is needed to connect to the actuators
    Process process = new ProcessBuilder("src\\actuatorapp\\VirtualHub.exe").start();
    //{"yocto_addr":"10FAD","payload":{"value":true},"type":"control"}

    api = new Socket("10.42.72.25", 8082);
    OutputStreamWriter osw = new OutputStreamWriter(api.getOutputStream(), StandardCharsets.UTF_8);
    InputStreamReader isr = new InputStreamReader(api.getInputStream(), StandardCharsets.UTF_8);

    //Sends JSON authentication to CommandAPI
    JSONObject secret = new JSONObject();
    secret.put("type", "authenticate");
    secret.put("secret", "testpass");
    osw.write(secret.toString() + "\r\n");
    osw.flush();//from   w  w w. j a  v a2  s .c  om
    System.out.println("sent");

    //Waits and recieves JSON authentication response
    BufferedReader br = new BufferedReader(isr);
    JSONObject response = new JSONObject(br.readLine());
    System.out.println(response.toString());
    if (!response.getBoolean("success")) {
        System.err.println("Invalid API secret");
        System.exit(1);
    }

    try {
        while (true) {
            //JSON object will contain message from the server
            JSONObject type = getCommand(br);
            //Forward the command to be processed (will find out which actuators to turn on/off)
            commandFromApi(type);
        }
    } catch (Exception e) {
        System.out.println("Error listening to api");
    }

}

From source file:com.bunjlabs.fuga.foundation.content.InputStreamContent.java

@Override
public String asString() {
    return asString(StandardCharsets.UTF_8);
}

From source file:com.blackducksoftware.integration.hub.detect.detector.go.GopkgLockParserTest.java

@Test
public void gopkgParserTest() throws IOException {
    final GopkgLockParser gopkgLockParser = new GopkgLockParser(new ExternalIdFactory());
    final String gopkgLockContents = IOUtils.toString(getClass().getResourceAsStream("/go/Gopkg.lock"),
            StandardCharsets.UTF_8);
    final DependencyGraph dependencyGraph = gopkgLockParser.parseDepLock(gopkgLockContents);
    Assert.assertNotNull(dependencyGraph);

    DependencyGraphResourceTestUtil.assertGraph("/go/Go_GopkgExpected_graph.json", dependencyGraph);
}

From source file:org.apache.kylin.jdbc.TestUtil.java

public static HttpResponse mockHttpResponse(int statusCode, String message, String body) {
    HttpResponse response = Mockito.mock(HttpResponse.class);
    Mockito.when(response.getStatusLine())
            .thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode, message));
    Mockito.when(response.getEntity()).thenReturn(new StringEntity(body, StandardCharsets.UTF_8));
    return response;
}

From source file:com.rodrigodev.xgen4j_table_generator.test.common.StringUtils.java

public static String fromInputStream(InputStream anInputStream) {
    return unchecked(() -> IOUtils.toString(anInputStream, StandardCharsets.UTF_8));
}

From source file:com.joyent.manta.client.multipart.TestMultipartManagerTest.java

public void canDoMultipartUpload() throws IOException {
    TestMultipartUpload upload = manager.initiateUpload("/user/stor/testobject");

    MantaMultipartUploadPart[] parts = new MantaMultipartUploadPart[] {
            manager.uploadPart(upload, 1, "Line 1\n"), manager.uploadPart(upload, 2, "Line 2\n"),
            manager.uploadPart(upload, 3, "Line 3\n"), manager.uploadPart(upload, 4, "Line 4\n"),
            manager.uploadPart(upload, 5, "Line 5") };

    Stream<MantaMultipartUploadTuple> partsStream = Stream.of(parts);

    manager.complete(upload, partsStream);

    String actual = FileUtils.readFileToString(upload.getContents(), StandardCharsets.UTF_8);

    String expected = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5";

    Assert.assertEquals(actual, expected);
}