Example usage for com.google.common.base Charsets UTF_8

List of usage examples for com.google.common.base Charsets UTF_8

Introduction

In this page you can find the example usage for com.google.common.base Charsets UTF_8.

Prototype

Charset UTF_8

To view the source code for com.google.common.base Charsets UTF_8.

Click Source Link

Document

UTF-8: eight-bit UCS Transformation Format.

Usage

From source file:ui.main.console.ConsoleMain.java

public static void main(String[] args) throws IOException {

    CompilerController compiler = new CompilerController(new ShellConsole());

    URL url = Resources.getResource("tests/memoTest1.txt");
    String source = Resources.toString(url, Charsets.UTF_8);

    compiler.interpret(source);/* w w  w.ja v  a2 s. c  o  m*/

}

From source file:se.kth.karamel.client.api.Driver.java

public static void main(String[] args) throws IOException, KaramelException, InterruptedException {

    //Karamel will read your ssh-key pair from the default location (~/.ssh/id_rsa and ~/.ssh/id_rsa/id_rsa.pub) in 
    //the unix-based systems. It uses your key-pair for ec2, so please make sure you have them provided before start 
    //running this program

    KaramelApi api = new KaramelApiImpl();
    //give your own yaml file
    String ymlString = Resources.toString(
            Resources.getResource("se/kth/karamel/client/model/test-definitions/hiway.yml"), Charsets.UTF_8);
    //since api works with json you will need to convert your yaml to json
    String json = api.yamlToJson(ymlString);

    //pass in your ec2 credentials here, 
    Ec2Credentials credentials = new Ec2Credentials();
    credentials.setAccessKey("<ec2-accoun-id>");
    credentials.setSecretKey("<ec2-access-key>");
    if (!api.updateEc2CredentialsIfValid(credentials))
        throw new IllegalThreadStateException("Ec2 credentials is not valid");

    //this is an async call, you will need to pull status of your cluster periodically with the forthcoming call
    api.startCluster(json);//w  w w . j a va2s  .c o m

    long ms1 = System.currentTimeMillis();
    while (ms1 + 6000000 > System.currentTimeMillis()) {
        //the name of the cluster should be equal to the one you specified in your yaml file
        String clusterStatus = api.getClusterStatus("hiway");
        logger.debug(clusterStatus);
        Thread.currentThread().sleep(60000);
    }
}

From source file:com.xemantic.tadedon.gwt.field.rebind.StringTemplateViewer.java

public static void main(String[] args) throws IOException {
    URL url = UiFieldAccessorGenerator.class.getResource("UiFieldAccessor.template");
    String templateFile = Resources.toString(url, Charsets.UTF_8);
    StringTemplate template = new StringTemplate(templateFile, DefaultTemplateLexer.class);
    template.setAttribute("year", Calendar.getInstance().get(Calendar.YEAR));
    template.setAttribute("date", new Date());
    template.setAttribute("package", "com.example");
    template.setAttribute("className", "UiFieldAccessorDemo_Impl");
    template.setAttribute("ownerType", "FooOwner");
    template.setAttribute("fields", Arrays.asList("foo", "bar"));
    System.out.println(template.toString());
}

From source file:org.apache.tika.example.SpringExample.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "org/apache/tika/example/spring.xml" });
    Parser parser = context.getBean("tika", Parser.class);
    parser.parse(new ByteArrayInputStream("Hello, World!".getBytes(Charsets.UTF_8)),
            new WriteOutContentHandler(System.out), new Metadata(), new ParseContext());
}

From source file:org.glowroot.benchmark.ResultFormatter.java

public static void main(String[] args) throws IOException {
    File resultFile = new File(args[0]);

    Scores scores = new Scores();
    double baselineStartupTime = -1;
    double glowrootStartupTime = -1;

    ObjectMapper mapper = new ObjectMapper();
    String content = Files.toString(resultFile, Charsets.UTF_8);
    content = content.replaceAll("\n", " ");
    ArrayNode results = (ArrayNode) mapper.readTree(content);
    for (JsonNode result : results) {
        String benchmark = result.get("benchmark").asText();
        benchmark = benchmark.substring(0, benchmark.lastIndexOf('.'));
        ObjectNode primaryMetric = (ObjectNode) result.get("primaryMetric");
        double score = primaryMetric.get("score").asDouble();
        if (benchmark.equals(StartupBenchmark.class.getName())) {
            baselineStartupTime = score;
            continue;
        } else if (benchmark.equals(StartupWithGlowrootBenchmark.class.getName())) {
            glowrootStartupTime = score;
            continue;
        }/*from  w w w.j a  v  a2  s  .co m*/
        ObjectNode scorePercentiles = (ObjectNode) primaryMetric.get("scorePercentiles");
        double score50 = scorePercentiles.get("50.0").asDouble();
        double score95 = scorePercentiles.get("95.0").asDouble();
        double score99 = scorePercentiles.get("99.0").asDouble();
        double score999 = scorePercentiles.get("99.9").asDouble();
        double score9999 = scorePercentiles.get("99.99").asDouble();
        double allocatedBytes = getAllocatedBytes(result);
        if (benchmark.equals(ServletBenchmark.class.getName())) {
            scores.baselineResponseTimeAvg = score;
            scores.baselineResponseTime50 = score50;
            scores.baselineResponseTime95 = score95;
            scores.baselineResponseTime99 = score99;
            scores.baselineResponseTime999 = score999;
            scores.baselineResponseTime9999 = score9999;
            scores.baselineAllocatedBytes = allocatedBytes;
        } else if (benchmark.equals(ServletWithGlowrootBenchmark.class.getName())) {
            scores.glowrootResponseTimeAvg = score;
            scores.glowrootResponseTime50 = score50;
            scores.glowrootResponseTime95 = score95;
            scores.glowrootResponseTime99 = score99;
            scores.glowrootResponseTime999 = score999;
            scores.glowrootResponseTime9999 = score9999;
            scores.glowrootAllocatedBytes = allocatedBytes;
        } else {
            throw new AssertionError(benchmark);
        }
    }
    System.out.println();
    printScores(scores);
    if (baselineStartupTime != -1) {
        System.out.println("STARTUP");
        System.out.format("%25s%14s%14s%n", "", "baseline", "glowroot");
        printLine("Startup time (avg)", "ms", baselineStartupTime, glowrootStartupTime);
    }
    System.out.println();
}

From source file:de.flapdoodle.guava.buildsupport.ExtractMarkdownFromCode.java

public static void main(String[] args) {
    String sourceFileName = args[0];
    String destFileName = args[1];

    try {//from   w w w .  jav a  2s. co  m
        String markDown = extractMarkdown(sourceFileName);
        Files.write(markDown, new File(destFileName), Charsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException("could not extract markdown", e);
    }
}

From source file:kn.uni.gis.dataimport.FormatStrangeFlickrFormat.java

License:asdf

public static void main(String[] args) throws IOException {
    Iterable<String> readLines = filterNulls(concatLines(Files.readLines(new File(INPUT), Charsets.UTF_8)));
    // BufferedReader reader = Files
    // .newReader(new File(INPUT), Charsets.UTF_8);
    // 1,20,12/*from  www  .  j av  a2  s  . com*/
    Files.write(Joiner.on("\n").skipNulls().join(Iterables.transform(readLines, new Function<String, String>() {

        @Override
        public String apply(String input) {
            // System.out.println(input);
            String[] split = input.split(";");

            if (equalss(split[0], "524", "567", "2284", "2720")) {
                return null;
            }

            assertNumbers(split);

            String asdf = Joiner.on("\t").join(split[0], split[19], split[20], "Z", "M", split[3], "");

            System.out.println(asdf);
            return asdf;
        }

        private void assertNumbers(String[] split) {
            if (!!!split[0].equals("Field1")) {
                Preconditions.checkArgument(Double.valueOf(split[19].replace(',', '.')) > 13,
                        split[19] + Arrays.toString(split));
                Preconditions.checkArgument(Double.valueOf(split[20].replace(',', '.')) > 52,
                        split[20] + Arrays.toString(split));
            }
        }
    })).replaceAll(",", "."), new File(OUTPUT), Charsets.UTF_8);
}

From source file:com.facebook.buck.rules.RocksDBMetadataDumper.java

public static void main(String[] args) throws RocksDBException {
    if (args.length < 1 || args.length > 2) {
        System.err.println("Usage: dump-rocksdb-metadata DB [TARGET]");
        System.exit(1);/* w  w  w  .  j  a  v a  2 s .c om*/
    }
    String dbPath = args[0];
    String targetStr = "";
    if (args.length == 2) {
        targetStr = args[1] + "\0";
        if (!targetStr.startsWith("//")) {
            targetStr = "//" + targetStr;
        }
    }
    RocksDB.loadLibrary();
    try (Options options = new Options();
            RocksDB db = RocksDB.open(options, dbPath);
            RocksIterator it = db.newIterator()) {
        byte[] target = targetStr.getBytes(Charsets.UTF_8);
        it.seek(target);
        for (it.seek(target); it.isValid() && startsWith(it.key(), target); it.next()) {
            String[] key = new String(it.key(), Charsets.UTF_8).split("\0");
            String targetPiece = key[0];
            String metaPiece = key[1];
            String value = new String(it.value(), Charsets.UTF_8);
            System.out.format("%s %s %s%n", targetPiece, metaPiece, value);
        }
    }
}

From source file:teetime.util.BucketTimingsReader.java

public static void main(final String[] args) throws IOException {
    final String fileName = args[0];

    final Long[] currentTimings = new Long[10000];
    int processedLines = 0;
    final List<Long> buckets = new LinkedList<Long>();

    LOGGER.trace("Reading " + fileName);
    final CharSource charSource = Files.asCharSource(new File(fileName), Charsets.UTF_8);
    final BufferedReader bufferedStream = charSource.openBufferedStream();
    String line;/* w w  w.j  av a 2  s  .  c  om*/
    while (null != (line = bufferedStream.readLine())) {
        final String[] strings = line.split(";");
        final Long timing = new Long(strings[1]);
        currentTimings[processedLines] = timing;
        processedLines++;
        if (currentTimings.length == processedLines) {
            // Long aggregatedTimings = StatisticsUtil.calculateQuintiles(Arrays.asList(currentTimings)).get(0.5);
            final Long aggregatedTimings = StatisticsUtil.calculateAverage(Arrays.asList(currentTimings));
            buckets.add(aggregatedTimings);
            processedLines = 0;
        }
    }

    LOGGER.trace("#buckets: " + buckets.size());

    final List<Long> durationsInNs = buckets.subList(buckets.size() / 2, buckets.size());

    LOGGER.trace("Calculating quantiles...");
    final Map<Double, Long> quintiles = StatisticsUtil.calculateQuintiles(durationsInNs);
    LOGGER.info(StatisticsUtil.getQuantilesString(quintiles));

    final long confidenceWidth = StatisticsUtil.calculateConfidenceWidth(durationsInNs);
    LOGGER.info("Confidence width: " + confidenceWidth);
}

From source file:edu.cmu.cs.lti.ark.fn.parsing.FrameFeaturesCache.java

public static void main(String[] args) throws IOException {
    FNModelOptions opts = new FNModelOptions(args);
    String eventsFile = opts.eventsFile.get();
    String spanFile = opts.spansFile.get();
    String frFile = opts.trainFrameFile.get();
    final List<String> frameLines = Files.readLines(new File(frFile), Charsets.UTF_8);
    final LocalFeatureReading lfr = new LocalFeatureReading(eventsFile, spanFile, frameLines);
    final List<FrameFeatures> frameFeaturesList = lfr.readLocalFeatures();
    SerializedObjects.writeSerializedObject(frameFeaturesList, opts.frameFeaturesCacheFile.get());
}