Example usage for java.nio.charset Charset defaultCharset

List of usage examples for java.nio.charset Charset defaultCharset

Introduction

In this page you can find the example usage for java.nio.charset Charset defaultCharset.

Prototype

Charset defaultCharset

To view the source code for java.nio.charset Charset defaultCharset.

Click Source Link

Usage

From source file:com.nsdr.json.JsonPathTest.java

@Test
public void hello() throws URISyntaxException, IOException {
    Path path = Paths.get(getClass().getResource("/europeana-oai.json").toURI());
    List<String> lines = Files.readAllLines(path, Charset.defaultCharset());

    List<JsonBranch> paths = new ArrayList<>();
    paths.add(new JsonBranch("@about", "$.['edm:ProvidedCHO'][0]['@about']", JsonBranch.Category.MANDATORY));
    paths.add(new JsonBranch("Proxy/dc:title",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:title']",
            JsonBranch.Category.MANDATORY, JsonBranch.Category.DESCRIPTIVENESS,
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.IDENTIFICATION,
            JsonBranch.Category.MULTILINGUALITY));
    paths.add(new JsonBranch("Proxy/dcterms:alternative",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:alternative']",
            JsonBranch.Category.DESCRIPTIVENESS, JsonBranch.Category.SEARCHABILITY,
            JsonBranch.Category.IDENTIFICATION, JsonBranch.Category.MULTILINGUALITY));
    paths.add(new JsonBranch("Proxy/dc:description",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:description']",
            JsonBranch.Category.MANDATORY, JsonBranch.Category.DESCRIPTIVENESS,
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.IDENTIFICATION, JsonBranch.Category.MULTILINGUALITY));
    paths.add(new JsonBranch("Proxy/dc:creator",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:creator']",
            JsonBranch.Category.DESCRIPTIVENESS, JsonBranch.Category.SEARCHABILITY,
            JsonBranch.Category.CONTEXTUALIZATION, JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dc:publisher",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:publisher']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dc:contributor",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:contributor']",
            JsonBranch.Category.SEARCHABILITY));
    paths.add(new JsonBranch("Proxy/dc:type",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:type']",
            JsonBranch.Category.MANDATORY, JsonBranch.Category.SEARCHABILITY,
            JsonBranch.Category.CONTEXTUALIZATION, JsonBranch.Category.IDENTIFICATION,
            JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dc:identifier",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:identifier']",
            JsonBranch.Category.IDENTIFICATION));
    paths.add(new JsonBranch("Proxy/dc:language",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:language']",
            JsonBranch.Category.DESCRIPTIVENESS, JsonBranch.Category.MULTILINGUALITY));
    paths.add(new JsonBranch("Proxy/dc:coverage",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:coverage']",
            JsonBranch.Category.MANDATORY, JsonBranch.Category.SEARCHABILITY,
            JsonBranch.Category.CONTEXTUALIZATION, JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dcterms:temporal",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:temporal']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dcterms:spatial",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:spatial']",
            JsonBranch.Category.MANDATORY, JsonBranch.Category.SEARCHABILITY,
            JsonBranch.Category.CONTEXTUALIZATION, JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dc:subject",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:subject']",
            JsonBranch.Category.MANDATORY, JsonBranch.Category.DESCRIPTIVENESS,
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.MULTILINGUALITY));
    paths.add(new JsonBranch("Proxy/dc:date",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:date']",
            JsonBranch.Category.IDENTIFICATION, JsonBranch.Category.BROWSING, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dcterms:created",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:created']",
            JsonBranch.Category.IDENTIFICATION, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dcterms:issued",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:issued']",
            JsonBranch.Category.IDENTIFICATION, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dcterms:extent",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:extent']",
            JsonBranch.Category.DESCRIPTIVENESS, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dcterms:medium",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:medium']",
            JsonBranch.Category.DESCRIPTIVENESS, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dcterms:provenance",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:provenance']",
            JsonBranch.Category.DESCRIPTIVENESS));
    paths.add(new JsonBranch("Proxy/dcterms:hasPart",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:hasPart']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dcterms:isPartOf",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dcterms:isPartOf']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/dc:format",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:format']",
            JsonBranch.Category.DESCRIPTIVENESS, JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dc:source",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:source']",
            JsonBranch.Category.DESCRIPTIVENESS));
    paths.add(new JsonBranch("Proxy/dc:rights",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:rights']",
            JsonBranch.Category.REUSABILITY));
    paths.add(new JsonBranch("Proxy/dc:relation",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['dc:relation']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/edm:isNextInSequence",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['edm:isNextInSequence']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.CONTEXTUALIZATION,
            JsonBranch.Category.BROWSING));
    paths.add(new JsonBranch("Proxy/edm:type",
            "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')]['edm:type']",
            JsonBranch.Category.SEARCHABILITY, JsonBranch.Category.BROWSING));

    for (int i = 0; i < lines.size(); i++) {
        Object document = Configuration.defaultConfiguration().jsonProvider().parse(lines.get(i));
        double j = 0.0;
        Map<String, double[]> stat = new HashMap<>();
        stat.put("total", new double[] { 0.0, 0.0 });
        for (JsonBranch.Category category : JsonBranch.Category.values()) {
            stat.put(category.name(), new double[] { 0.0, 0.0 });
        }//from w w w.j  av  a2  s.  co  m
        for (JsonBranch jp : paths) {
            Object value = JsonPath.read(document, jp.getJsonPath());
            increaseTotal(stat, jp.getCategories());
            if (value.getClass() == JSONArray.class) {
                if (!((JSONArray) value).isEmpty()) {
                    increaseInstance(stat, jp.getCategories());
                }
            } else if (value.getClass() == String.class) {
                if (StringUtils.isNotBlank((String) value)) {
                    increaseInstance(stat, jp.getCategories());
                }
            } else {
                System.err.println(jp.getLabel() + " value.getClass(): " + value.getClass());
                System.err.println(jp.getLabel() + ": " + value);
            }
        }
        for (String key : stat.keySet()) {
            System.err.println(
                    key + ": " + (stat.get(key)[1] == 0.0 ? 0.0 : (stat.get(key)[1] / stat.get(key)[0])));
        }
    }

}

From source file:com.hurence.logisland.classloading.PluginLoader.java

/**
 * Scan for plugins./*w ww .j  a v a2 s.  co m*/
 */
private static void scanAndRegisterPlugins() {
    Set<URL> urls = new HashSet<>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    while (cl != null) {
        if (cl instanceof URLClassLoader) {
            urls.addAll(Arrays.asList(((URLClassLoader) cl).getURLs()));
            cl = cl.getParent();
        }
    }

    for (URL url : urls) {
        try {
            Archive archive = null;
            try {
                archive = new JarFileArchive(
                        new File(URLDecoder.decode(url.getFile(), Charset.defaultCharset().name())), url);
            } catch (Exception e) {
                //silently swallowing exception. just skip the archive since not an archive
            }
            if (archive == null) {
                continue;
            }
            Manifest manifest = archive.getManifest();
            if (manifest != null) {
                String exportedPlugins = manifest.getMainAttributes()
                        .getValue(ManifestAttributes.MODULE_EXPORTS);
                if (exportedPlugins != null) {
                    String version = StringUtils.defaultIfEmpty(
                            manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION),
                            "UNKNOWN");

                    logger.info("Loading components from module {}", archive.getUrl().toExternalForm());

                    final Archive arc = archive;

                    if (StringUtils.isNotBlank(exportedPlugins)) {
                        Arrays.stream(exportedPlugins.split(",")).map(String::trim).forEach(s -> {
                            if (registry.putIfAbsent(s, PluginClassloaderBuilder.build(arc)) == null) {
                                logger.info("Registered component '{}' version '{}'", s, version);
                            }

                        });
                    }
                }
            }

        } catch (Exception e) {
            logger.error("Unable to load components from " + url.toExternalForm(), e);
        }
    }
}

From source file:de.qaware.cloud.deployer.plugin.extension.SSLExtensionTest.java

@Test
public void testSetCertificate() throws IOException, EnvironmentConfigException, ResourceConfigException {
    String cert = "CERT";
    File certFile = folder.newFile();
    FileUtils.writeStringToFile(certFile, "CERT", Charset.defaultCharset());

    SSLExtension extension = new SSLExtension();
    extension.setCertificate(certFile);// ww w .j  ava2s  .  co m
    assertEquals(cert, extension.getCertificate());
}

From source file:fi.jumi.core.stdout.SynchronizedPrintStreamTest.java

/**
 * For example {@link Throwable#printStackTrace} does this, we must be careful to always acquire a lock on the
 * monitor of the PrintStream first, before all other locks.
 *//*from  w  w  w  .java  2  s .  c om*/
@Test
public void does_not_deadlock_if_somebody_locks_in_the_PrintStream_externally() throws Exception {
    final int ITERATIONS = 10;
    PrintStream printStream = SynchronizedPrintStream.create(new NullOutputStream(), Charset.defaultCharset(),
            lock);

    // will fail with a test timeout if a deadlock happens
    runConcurrently(() -> {
        // what Thread.printStackTrace() would do
        synchronized (printStream) {
            for (int i = 0; i < ITERATIONS; i++) {
                Thread.yield();
                printStream.print("X");
            }
        }
    }, () -> {
        // what a normal printer would do
        for (int i = 0; i < ITERATIONS; i++) {
            Thread.yield();
            printStream.print("X");
        }
    });
}

From source file:com.thinkbiganalytics.spring.FileResourceService.java

public String resourceAsString(Resource resource) {
    try {/*  w  w w.ja v  a 2  s. c  o m*/
        if (resource != null) {
            InputStream is = resource.getInputStream();
            return IOUtils.toString(is, Charset.defaultCharset());
        }
    } catch (IOException e) {
        log.error("Unable to load file {} ", resource.getFilename(), e);
    }
    return null;
}

From source file:br.unb.bionimbuz.storage.bucket.methods.CloudMethodsAmazonGoogle.java

@Override
public void StorageAuth(StorageProvider sp) throws Exception {

    switch (sp) {

    case AMAZON: {

        byte[] encoded = Files.readAllBytes(Paths.get(authFolder + "AwsCredentials.txt"));
        String fileContent = new String(encoded, Charset.defaultCharset());
        //System.out.println("AuthString: " + fileContent);
        String accessKeyID, accessKey;
        int delimiter = fileContent.indexOf(':');
        accessKeyID = fileContent.substring(0, delimiter);
        accessKey = fileContent.substring(delimiter + 1);
        AWSCredentials credentials = new BasicAWSCredentials(accessKeyID, accessKey);
        s3client = new AmazonS3Client(credentials);

        break;//  w w  w .j av a 2 s . co m
    }
    case GOOGLE: {

        String command = gcloudFolder + "gcloud auth activate-service-account --key-file=" + authFolder
                + "GoogleCredentials.json";
        ExecCommand(command);

        break;
    }
    default: {
        throw new Exception("Provedor incorreto!");
    }
    }
}

From source file:br.unb.cic.bionimbuz.storage.bucket.methods.CloudMethodsAmazonGoogle.java

@Override
public void StorageAuth(StorageProvider sp) throws Exception {

    switch (sp) {

    case AMAZON: {

        byte[] encoded = Files.readAllBytes(Paths.get(authFolder + "accesskey.txt"));
        String fileContent = new String(encoded, Charset.defaultCharset());
        //System.out.println("AuthString: " + fileContent);
        String accessKeyID, accessKey;
        int delimiter = fileContent.indexOf(':');
        accessKeyID = fileContent.substring(0, delimiter);
        accessKey = fileContent.substring(delimiter + 1);
        AWSCredentials credentials = new BasicAWSCredentials(accessKeyID, accessKey);
        s3client = new AmazonS3Client(credentials);

        break;/*from  ww w.  j  a v  a2 s .c om*/
    }
    case GOOGLE: {

        String command = gcloudFolder + "gcloud auth activate-service-account --key-file=" + authFolder
                + "cred.json";
        ExecCommand(command);

        break;
    }
    default: {
        throw new Exception("Provedor incorreto!");
    }
    }
}

From source file:com.programmablefun.ide.editor.TextMateThemeLoader.java

public TextMateThemeLoader(InputStream is) throws IOException {
    this.stylesheet = new Stylesheet.JsonStylesheet();
    StringWriter w = new StringWriter();
    IOUtils.copy(is, w, Charset.defaultCharset());
    String content = removeXmlComments(w.toString());
    try {//from   w  ww .  j a  v  a 2 s  .co m
        this.plist = Plist.fromXml(content);
    } catch (XmlParseException e) {
        throw new IOException(e);
    }
}

From source file:com.fns.grivet.service.ClassRegistryServiceTest.java

@Test
public void testRegisterThenGetThenAll() throws IOException {
    Resource r = resolver.getResource("classpath:TestType.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    JSONObject payload = new JSONObject(json);

    String type = classRegistryService.register(payload);
    Assertions.assertEquals("TestType", type);

    JSONObject jo = classRegistryService.get("TestType");
    Assertions.assertEquals(payload.toString(), jo.toString());

    JSONArray ja = classRegistryService.all();
    Assertions.assertEquals(payload.toString(), ja.get(0).toString());
}

From source file:com.adaptris.core.common.PayloadStreamInputParameterTest.java

@Test
public void testExtract() throws Exception {
    PayloadStreamInputParameter p = new PayloadStreamInputParameter();
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT.getBytes());
    try (InputStream in = p.extract(msg)) {
        List<String> strings = IOUtils.readLines(in, Charset.defaultCharset());
        assertEquals(1, strings.size());
        assertEquals(TEXT, strings.get(0));
    }/*w w w.j  a v  a2s . c o  m*/
}