List of usage examples for java.nio.charset StandardCharsets UTF_8
Charset UTF_8
To view the source code for java.nio.charset StandardCharsets UTF_8.
Click Source Link
From source file:com.grantingersoll.opengrok.analysis.perl.TestPerlSymbolTokenizer.java
@Test public void test() throws Exception { String input;/*from ww w . jav a2s . c om*/ try (InputStream stream = TestPerlSymbolTokenizer.class.getResourceAsStream("main.pl"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// #!/usr/bin/perl "DBI", //// use DBI; //// "database", //// my $database='dbi:DB2:sample'; "user", //// my $user=''; "password", //// my $password=''; //// "dbh", "DBI", "database", "user", "password", //// my $dbh = DBI->connect($database, $user, $password) //// or die "Can't connect to $database: $DBI::errstr"; //// "sth", "dbh", "prepare", //// my $sth = $dbh->prepare( "SELECT", "firstnme", "lastname", //// q{ SELECT firstnme, lastname "FROM", "employee", //// FROM employee } //// ) //// or die "Can't prepare statement: $DBI::errstr"; //// "rc", "sth", "execute", //// my $rc = $sth->execute //// or die "Can't execute statement: $DBI::errstr"; //// //// print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n"; //// print "$sth->{NAME}->[0]: $sth->{NAME}->[1]\n"; //// "firstnme", "lastname", "sth", "fetchrow", //// while (($firstnme, $lastname) = $sth->fetchrow()) { //// print "$firstnme: $lastname\n"; //// } //// //// # check for problems which may have terminated the fetch early "DBI", "errstr", "DBI", //// warn $DBI::errstr if $DBI::err; //// "sth", "finish", //// $sth->finish; "dbh", "disconnect", //// $dbh->disconnect; //// "item", "snazzle", /* TODO: handle POD formatted commentary! */ //// =item snazzle($) //// "The", "snazzle", "function", "will", "behave", "in", "the", "most", "spectacular", //// The snazzle() function will behave in the most spectacular "form", "that", "you", "can", "possibly", "imagine", "even", "excepting", //// form that you can possibly imagine, not even excepting "cybernetic", "pyrotechnics", //// cybernetic pyrotechnics. //// "cut", "back", "to", "the", "compiler", "nuff", "of", "this", "pod", "stuff", //// =cut back to the compiler, nuff of this pod stuff! //// "snazzle", //// sub snazzle($) { "thingie", //// my $thingie = shift; //// } //// "x", //// my x; "x", //// $x=12345 # integer "x", //// $x=-54321 # negative integer "x", //// $x=12345.67 # floating point "x", "E23", /* TODO: handle full numeric syntax! */ //// $x=6.02E23 # scientific notation "x", //// $x=0xffff # hexadecimal "x", //// $x=0377 # octal "x", "_294_967_296" /* TODO: handle full numeric syntax! */ //// $x=4_294_967_296 # underline for legibility //// //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:com.expedia.seiso.web.httpmessageconverter.ItemKeyHttpMessageConverterTests.java
private void setUpTestData() throws Exception { this.inputStream = new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8)); when(inputMessage.getBody()).thenReturn(inputStream); }
From source file:com.spartasystems.holdmail.domain.MessageContentPart.java
public String getContentString() { return this.content == null ? null : new String(content, StandardCharsets.UTF_8); }
From source file:ee.ria.xroad.common.conf.globalconfextension.OcspFetchIntervalSchemaValidator.java
/** * Validates the given XML file/*from w w w . ja v a 2 s.com*/ */ public void validateFile(String fileName) throws Exception { String xml = FileUtils.readFileToString(new File(fileName), StandardCharsets.UTF_8.toString()); validate(xml); }
From source file:com.grantingersoll.opengrok.analysis.clojure.TestClojureSymbolTokenizer.java
@Test public void test() throws Exception { String input;/* w w w. j a va 2 s.c o m*/ try (InputStream stream = TestClojureSymbolTokenizer.class.getResourceAsStream("main.clj"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// ;;;; From https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/main.clj //// //// ; Copyright (c) Rich Hickey. All rights reserved. //// ; The use and distribution terms for this software are covered by the //// ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) //// ; which can be found in the file epl-v10.html at the root of this distribution. //// ; By using this software in any fashion, you are agreeing to be bound by //// ; the terms of this license. //// ; You must not remove this notice, or any other, from this software. //// //// ; Author: Stuart Halloway //// //// "clojure.test-clojure.main", //// (ns clojure.test-clojure.main ":use", "clojure.test", //// (:use clojure.test "clojure.test-helper", ":only", "platform-newlines", //// [clojure.test-helper :only [platform-newlines]]) ":require", "clojure.main", ":as", "main", //// (:require [clojure.main :as main])) //// "deftest", "eval-opt", //// (deftest eval-opt "testing", //// (testing "evals and prints forms" "is", "platform-newlines", "clojure.main/eval-opt", //// (is (= (platform-newlines "2\n4\n") (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)"))))) //// "testing", //// (testing "skips printing nils" "is", "platform-newlines", "clojure.main/eval-opt", //// (is (= (platform-newlines ":a\n:c\n") (with-out-str (#'clojure.main/eval-opt ":a nil :c"))))) //// "testing", //// (testing "does not block access to *in* (#299)" //// (with-in-str "(+ 1 1)" "is", "platform-newlines", "clojure.main/eval-opt", //// (is (= (platform-newlines "(+ 1 1)\n") (with-out-str (#'clojure.main/eval-opt "(read)"))))))) //// "with-err-str", //// (defmacro with-err-str //// "Evaluates exprs in a context in which *err* is bound to a fresh //// StringWriter. Returns the string created by any nested printing //// calls." "&", "body", //// [& body] "s", "java.io.StringWriter", //// `(let [s# (new java.io.StringWriter) "p", "java.io.PrintWriter", "s", //// p# (new java.io.PrintWriter s#)] "p", //// (binding [*err* p#] "@body", //// ~@body "s", //// (str s#)))) //// "run-repl-and-return-err", //// (defn run-repl-and-return-err //// "Run repl, swallowing stdout and returing stderr." "in-str", //// [in-str] "with-err-str", //// (with-err-str //// (with-out-str "in-str", //// (with-in-str in-str "main/repl", //// (main/repl))))) //// //// ;argh - test fragility, please fix "_", "deftest", "repl-exception-safety", //// #_(deftest repl-exception-safety "testing", //// (testing "catches and prints exception on bad equals" "is", //// (is (re-matches #"java\.lang\.NullPointerException\r?\n" "run-repl-and-return-err", //// (run-repl-and-return-err //// "(proxy [Object] [] (equals [o] (.toString nil)))"))))) }; assertAnalyzesTo(analyzer, input, output); }
From source file:com.grantingersoll.opengrok.analysis.java.TestJavaSymbolTokenizer.java
@Test public void test() throws Exception { String input;/*from w w w . ja va 2 s . com*/ try (InputStream stream = TestJavaSymbolTokenizer.class.getResourceAsStream("Sample.java"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// /* //// * CDDL HEADER START //// * //// * The contents of this file are subject to the terms of the //// * Common Development and Distribution License (the "License"). //// * You may not use this file except in compliance with the License. //// * //// * See LICENSE.txt included in this distribution for the specific //// * language governing permissions and limitations under the License. //// * //// * When distributing Covered Code, include this CDDL HEADER in each //// * file and include the License file at LICENSE.txt. //// * If applicable, add the following below this CDDL HEADER, with the //// * fields enclosed by brackets "[]" replaced with your own identifying //// * information: Portions Copyright [yyyy] [name of copyright owner] //// * //// * CDDL HEADER END //// */ //// //// /* //// * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. //// */ "org", "opensolaris", "opengrok", "analysis", "java", //// package org.opensolaris.opengrok.analysis.java; //// "Sample", //// public class Sample { //// "String", "MY_MEMBER", //// static private String MY_MEMBER = "value"; //// "Sample", //// public Sample() { //// //// } //// "Method", "arg", //// public int Method(int arg) { "res", //// int res = 5; //// "res", "arg", //// res += arg; //// "InnerClass", "i", "InnerClass", //// InnerClass i = new InnerClass(); //// "i", "InnerMethod", "length", "res", //// return i.InnerMethod().length() * res; //// } //// "InnerClass", //// private class InnerClass { //// "String", "InnerMethod", //// public String InnerMethod() { //// // somthing } */ //// /* }}} //// multi-line comment }{} //// */ //// "System", "out", "print", //// System.out.print("I'm so useless"); //// //// return "Why do robots need to drink?"; //// } //// //// } //// //// } //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:io.appium.java_client.imagecomparison.ComparisonResult.java
/** * Returns the visualization of the matching result. * * @return The visualization of the matching result represented as base64-encoded PNG image. *//* w ww.j a v a2 s . c om*/ public byte[] getVisualization() { verifyPropertyPresence(VISUALIZATION); return ((String) getCommandResult().get(VISUALIZATION)).getBytes(StandardCharsets.UTF_8); }
From source file:com.grantingersoll.opengrok.analysis.python.TestPythonSymbolTokenizer.java
@Test public void test() throws Exception { String input;//from w w w .j ava 2 s. co m try (InputStream stream = TestPythonSymbolTokenizer.class.getResourceAsStream("main.py"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// #!/usr/bin/env python //// # //// //// # testing comment //// "getopt", //// import getopt "os", //// import os //// #import stat "string", //// import string "sys", //// import sys //// "datetime", //// import datetime "time", //// import time "math", //// import math "random", //// import random //// "SCRIPTHOME", "os", "path", "dirname", "sys", "argv", //// SCRIPTHOME=os.path.dirname(sys.argv[0]) //// "version_string", //// version_string = "0.4" //// "banner", //// def banner(): //// print """This is a multi //// string with mu //// ltiple lines //// """, //// //// "version", //// def version(): "version_string", //// print "version %s " % version_string, //// "MyClass", //// class MyClass: //// """A simple example class""" "i", //// i = 12345 "x", //// x = 0xdeadbeef "l", "L", /* TODO: support all numeric formats! */ //// l= 456L "z", //// z=14*8 "f", //// f=12.38 "i", "e", "j", /* TODO: support all numeric formats! */ //// i=3.14e-10j "ef", "e", /* TODO: support all numeric formats! */ //// ef=14e-13 "f", "self", //// def f(self): //// return 'hello world' //// "main", //// def main(): //// //// # supress RuntimeWarning for tempnam being insecure //// # warnings.filterwarnings( "ignore" ) //// //// # go ahead "x", "MyClass", //// x = MyClass() //// print "hello world", //// "version", //// version() //// //// # ----------------------------------------------------- "__name__", //// if __name__ == "__main__": "main", //// main() //// //// //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:org.pentaho.di.core.util.HttpClientUtil.java
/** * * @param response the httpresponse for processing * @param charset the charset used for getting HttpEntity * @param decode determines if the result should be decoded or not * @return HttpEntity in String representation using provided charset * @throws IOException/* ww w .j a va 2s .c o m*/ */ public static String responseToString(HttpResponse response, Charset charset, boolean decode) throws IOException { HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity, charset); EntityUtils.consume(entity); if (decode) { result = URLDecoder.decode(result, StandardCharsets.UTF_8.name()); } return result; }
From source file:com.falcon.orca.handlers.StandAloneHandler.java
@Override public void handle() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); Options options = createOptions();/* ww w .j a va 2s . co m*/ printOnCmd("Welcome to ORCA type --help | -h to see what ORCA can do."); try { String command = br.readLine(); while (command != null) { if (!StringUtils.isEmpty(command)) { try { String[] treatedCommandParts = treatCommands(command); commandLine = commandLineParser.parse(options, treatedCommandParts); if (commandLine.hasOption("start")) { if (manager != null && !manager.isTerminated()) { printOnCmd("Already running a job, please wait!!"); } else { RunDetails runDetails = createRunDetails(commandLine); if (runDetails.isBodyDynamic() || runDetails.isUrlDynamic()) { DataReader dataReader = new JsonFileReader(runDetails.getDataFilePath(), runDetails.getTemplateFilePath()); HashMap<String, HashMap<String, List<Object>>> dynDataFromFile = dataReader .readVariableValues(); HashMap<String, HashMap<String, DynVarUseType>> dynVarUseTypeFromFile = dataReader .readVariableUseType(); HashMap<String, List<Object>> bodyParams = null; String template = null; HashMap<String, DynVarUseType> bodyParamsUseType = null; HashMap<String, List<Object>> urlParams = null; HashMap<String, DynVarUseType> urlParamsUseType = null; if (runDetails.isBodyDynamic()) { bodyParams = dynDataFromFile.get("bodyData"); template = dataReader.readTemplate(); bodyParamsUseType = dynVarUseTypeFromFile.get("bodyVarUseType"); } if (runDetails.isUrlDynamic()) { urlParams = dynDataFromFile.get("urlData"); urlParamsUseType = dynVarUseTypeFromFile.get("urlVarUseType"); } HashMap<String, DynGenerator> generators = dataReader.readGenerators(); DynDataStore dataStore = new DynDataStore(bodyParams, urlParams, bodyParamsUseType, urlParamsUseType, generators, template, runDetails.getUrl()); manager = actorSystem.actorOf(Manager.props(runDetails, dataStore)); } else { manager = actorSystem.actorOf(Manager.props(runDetails, null)); } ManagerCommand managerCommand = new ManagerCommand(); managerCommand.setType(ManagerCommandType.START); manager.tell(managerCommand, manager); } } else if (commandLine.hasOption("stop")) { if (manager != null && !manager.isTerminated()) { ManagerCommand managerCommand = new ManagerCommand(); managerCommand.setType(ManagerCommandType.STOP); manager.tell(managerCommand, manager); printOnCmd("Job killed successfully."); } else { printOnCmd("No job running."); } } else if (commandLine.hasOption("exit")) { if (manager != null && !manager.isTerminated()) { ManagerCommand managerCommand = new ManagerCommand(); managerCommand.setType(ManagerCommandType.STOP); manager.tell(managerCommand, manager); } printOnCmd("Exiting the system gracefully now."); actorSystem.shutdown(); actorSystem.awaitTermination(new FiniteDuration(1, TimeUnit.MINUTES)); break; } else if (commandLine.hasOption("pause")) { if (manager != null && !manager.isTerminated()) { ManagerCommand managerCommand = new ManagerCommand(); managerCommand.setType(ManagerCommandType.PAUSE); manager.tell(managerCommand, manager); } else { printOnCmd("No active jobs to pause."); } } else if (commandLine.hasOption("resume")) { if (manager != null && !manager.isTerminated()) { ManagerCommand managerCommand = new ManagerCommand(); managerCommand.setType(ManagerCommandType.RESUME); manager.tell(managerCommand, manager); } else { printOnCmd("No paused job to resume."); } } else { printOnCmd(printHelpStandAloneMode()); } } catch (ParseException pe) { printOnCmd(printHelpStandAloneMode()); } catch (MalformedURLException me) { me.printStackTrace(); } } else { printOnCmd("", false); } command = br.readLine(); } } catch (IOException e) { printOnCmd("Something went wrong in reading input, please try again."); } }