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:love.sola.netsupport.util.RSAUtil.java

public static String encrypt(String value) {
    try {// ww w . ja v  a2s .  c o  m
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] encrypted = cipher.doFinal(value.getBytes(StandardCharsets.UTF_8));
        return Base64.encodeBase64String(encrypted);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.joyent.manta.http.entity.DigestedEntityTest.java

public void testWriteToProducesReliableDigest() throws Exception {
    String content = STRING_GENERATOR.generate(100);
    DigestedEntity entity = new DigestedEntity(new ExposedStringEntity(content, StandardCharsets.UTF_8),
            new FastMD5Digest());

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    entity.writeTo(out);/*from   www.ja  v  a2  s .  c o m*/
    byte[] initialDigest = entity.getDigest();

    // connection reset, httpclient performs a retry reusing the same entity
    out.reset();
    entity.writeTo(out);
    byte[] retryDigest = entity.getDigest();

    Assert.assertTrue(Arrays.equals(initialDigest, retryDigest),
            "Reuse of DigestedEntity produced differing digest for first retry");

    // connection reset again
    out.reset();
    entity.writeTo(out);
    byte[] extraRetryDigest = entity.getDigest();

    Assert.assertTrue(Arrays.equals(initialDigest, extraRetryDigest),
            "Reuse of DigestedEntity produced differing digest for second retry");
}

From source file:org.apache.cxf.transport.https.httpclient.PublicSuffixMatcherLoader.java

private static PublicSuffixMatcher load(final InputStream in) throws IOException {
    final PublicSuffixList list = new PublicSuffixListParser()
            .parse(new InputStreamReader(in, StandardCharsets.UTF_8));
    return new PublicSuffixMatcher(list.getRules(), list.getExceptions());
}

From source file:io.github.swagger2markup.utils.IOUtils.java

/**
 * Create a reader from specified {@code source}.<br>
 * Returned reader should be explicitly closed after use.
 *
 * @param uri source URI/* ww  w .  j  a v a  2 s  .  co  m*/
 * @return reader
 * @throws IOException if the connection cannot be opened
 */
public static Reader uriReader(URI uri) throws IOException {
    return new BufferedReader(new InputStreamReader(uri.toURL().openStream(), StandardCharsets.UTF_8));
}

From source file:com.ibm.watson.app.common.services.nlclassifier.model.NLClassifierTrainingData.java

public static NLClassifierTrainingData fromStream(InputStream stream) throws IOException {
    try (Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
        return gson.fromJson(reader, NLClassifierTrainingData.class);
    }/*from   w  w w .j a v  a2 s.  com*/
}

From source file:costumetrade.common.util.HttpClientUtils.java

public static String doPost(String url, HttpEntity httpEntity) {

    logger.info("?{}....", url);

    try (CloseableHttpClient httpclient = HttpClients.custom().build();) {
        HttpPost request = new HttpPost(url);
        request.setEntity(httpEntity);//  w ww  . jav a2  s  .  c  o m
        try (CloseableHttpResponse response = httpclient.execute(request);) {
            int statusCode = response.getStatusLine().getStatusCode();
            logger.info("?{}???{}", url, statusCode);
            if (HttpStatus.SC_OK == statusCode) {
                return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name());
            }
            throw new RuntimeException(String.format("?%s???%s", url, statusCode));
        }
    } catch (Exception e) {
        throw new RuntimeException(String.format("%s", url), e);
    }
}

From source file:inti.ws.spring.resource.minify.LessMinifier.java

@Override
public String minify(String original) throws LessException {
    LessCompiler lessCompiler = new LessCompiler();
    lessCompiler.setCompress(true);//from   w  w  w  .j av  a2  s  .  co  m
    lessCompiler.setEncoding(StandardCharsets.UTF_8.name());
    return lessCompiler.compile(original);
}

From source file:model.ARXkAnonymiser.java

public static ArrayList<String[]> kAnonimiseData(File csvFile, kAnonData[] kAnonRecords, int kAnon)
        throws IOException {

    /* Check file is of correct type / !null */
    if (csvFile == null || !FilenameUtils.getExtension(csvFile.getAbsolutePath()).equals("csv")) {
        System.out.println("ARXkAnon : invalid file");
        return null;
    }/*from w  w  w .j  a  v a  2  s. c  om*/

    /* Check kAnonData !null */
    if (kAnonRecords == null) {
        System.out.println("ARXkAnon : invalid records (null) ");
        return null;
    }

    /* Check valid input */
    if (kAnon <= 0) {
        System.out.println("ARXkAnon : invalid k Anon value");
        return null;
    }

    //return Arr;
    String[][] outputArr;

    // Define data
    Data data = Data.create(csvFile, StandardCharsets.UTF_8, ',');

    //create arraylist of hierarchies
    Hierarchy[] hierarchies = new Hierarchy[kAnonRecords.length];

    // Define hierarchies
    //Hierarchy age = Hierarchy.create(ageHeirarchyFile,StandardCharsets.UTF_8,',');

    Hierarchy recordHierarchy;
    AttributeType attribute;

    for (kAnonData record : kAnonRecords) {

        //create the Attribute type:
        switch (record.getAttributeType()) {
        //"Identifier","Quasi-Identifier","Sensitive","Insensitive"
        case "Identifier":
            attribute = AttributeType.IDENTIFYING_ATTRIBUTE;
            break;
        case "Quasi-Identifier":
            attribute = AttributeType.QUASI_IDENTIFYING_ATTRIBUTE;
            break;
        case "Sensitive":
            attribute = AttributeType.SENSITIVE_ATTRIBUTE;
            break;
        case "Insensitive":
            attribute = AttributeType.INSENSITIVE_ATTRIBUTE;
            break;
        default:
            attribute = AttributeType.IDENTIFYING_ATTRIBUTE;
        }

        if (record.getAnonHierarchy() != null) {
            recordHierarchy = Hierarchy.create(record.getAnonHierarchy(), StandardCharsets.UTF_8, ',');
            data.getDefinition().setAttributeType(record.getattributeTitle(), recordHierarchy);
        } else {
            data.getDefinition().setAttributeType(record.getattributeTitle(), attribute);
        }

    }

    // Create an instance of the anonymizer
    ARXAnonymizer anonymizer = new ARXAnonymizer();
    ARXConfiguration config = ARXConfiguration.create();
    config.addCriterion(new KAnonymity(kAnon));
    config.setMaxOutliers(1.0d);

    ARXResult result = anonymizer.anonymize(data, config);

    // Print info
    printResult(result, data);

    ArrayList<String[]> outputArrList = new ArrayList<>();

    // Process results
    //System.out.println(" - Transformed data:");
    Iterator<String[]> transformed = result.getOutput(false).iterator();
    while (transformed.hasNext()) {
        //System.out.print("   ");
        String[] transformedData = transformed.next();
        //System.out.println(Arrays.toString(transformedData));
        outputArrList.add(transformedData);
    }

    return outputArrList;

}

From source file:base.compilations.JavaCompilation.java

@Override
protected void writeUserCodeInto(File file, String code) throws IOException {
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file),
            StandardCharsets.UTF_8)) {
        writer.write(code);/*from   ww  w.j  ava 2 s  .co m*/
        writer.flush();
    }
}

From source file:org.n52.shetland.util.HTTP.java

public static String getAsString(URI uri) throws IOException {
    try (CloseableHttpResponse response = CLIENT.execute(new HttpGet(uri))) {
        HttpEntity entity = response.getEntity();
        String encoding = Optional.ofNullable(entity.getContentEncoding()).map(Header::getValue)
                .orElse(StandardCharsets.UTF_8.name());
        Charset charset = Charset.forName(encoding);
        try (InputStream is = entity.getContent(); Reader reader = new InputStreamReader(is, charset)) {
            return CharStreams.toString(reader);
        }// w  w w  . ja  v a  2s  .  c o  m
    }
}