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:fr.cnrs.sharp.test.UnificationRuleTest.java
@Test public void testUnification() { Model data = ModelFactory.createDefaultModel(); InputStream stream = new ByteArrayInputStream(inputGraph.getBytes(StandardCharsets.UTF_8)); RDFDataMgr.read(data, stream, Lang.TTL); data.write(System.out, "TTL"); logger.info("Graph size / BNodes : " + data.size() + "/" + Unification.countBN(data)); Assert.assertEquals(13, data.size()); Assert.assertEquals(3, Unification.countBN(data)); int nbSubst = 1; while (nbSubst > 0) { // UNIFICATION : 1. select substitutions List<Pair<RDFNode, RDFNode>> toBeMerged = Unification.selectSubstitutions(data); nbSubst = toBeMerged.size();/*from w ww. jav a 2s.c o m*/ logger.info("Found substitutions: " + nbSubst); // UNIFICATION : 2. effectively replacing blank nodes by matching nodes for (Pair<RDFNode, RDFNode> p : toBeMerged) { Unification.mergeNodes(p.getLeft(), p.getRight().asResource()); } logger.info("Graph size / BNodes with unified PROV inferences: " + data.size() + "/" + Unification.countBN(data)); nbSubst = Unification.selectSubstitutions(data).size(); logger.info("Found substitutions: " + nbSubst + " after merging"); } data.write(System.out, "TTL"); Assert.assertEquals(10, data.size()); Assert.assertEquals(1, Unification.countBN(data)); }
From source file:com.grantingersoll.opengrok.analysis.c.TestCSymbolTokenizer.java
@Test public void test() throws Exception { String input;/*from w w w . j a v a 2 s. co m*/ try (InputStream stream = TestCSymbolTokenizer.class.getResourceAsStream("sample.c"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// // compile me with gcc //// /* this is sample comment } */ "stdio", "h", //// #include <stdio.h> "string", "h", //// #include <string.h> //// "TEST", "x", "x", //// #define TEST(x) (x) //// "foo", "a", "b", //// int foo(int a, int b) { //// /* blah blah //// } //// */ //// "c", //// int c; "msg", //// const char *msg = "this is } sample { string"; "a", "b", //// if (a < b) { "strlen", "msg", //// return strlen(msg); //// } else { //// // }}}}} something to return "c", "TEST", "a", "TEST", "b", //// c = TEST(a) + TEST(b); //// } "c", //// return c; //// } //// "bar", "x", //// int bar(int x /* } */) //// { //// // another function "d", //// int d; "f", //// int f; "printf", "TEST", //// printf(TEST("test { message|$#@$!!#")); "d", "foo", //// d = foo(2, 4); "f", "foo", "x", "d", //// f = foo(x, d); //// //// /* return //// some //// rubish //// */ "d", "f", //// return d+f; //// } //// //// // main function "main", "argc", "argv", //// int main(int argc, char *argv[]) { "res", //// int res; "printf", //// printf("this is just a {sample}}"); //// "res", "bar", //// res = bar(20); "printf", "res", //// printf("result = {%d}\n", res); //// //// return 0; } //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:com.mh2c.LogGenerator.java
/** * Generates log lines and sends them to Kinesis. * * @param streamName Kinesis stream name * @param recsPerSecond number of records to send each second * @param numRecords total number of records to send *///ww w . j a v a2 s . c o m public void generate(String streamName, int recsPerSecond, int numRecords) throws InterruptedException { AmazonKinesisClient client = new AmazonKinesisClient(); int numPasses = (numRecords + recsPerSecond - 1) / recsPerSecond; int recordsLeft = numRecords; for (int i = 0; i < numPasses; i++) { int numToGenerate = Math.min(recordsLeft, recsPerSecond); for (int j = 0; j < numToGenerate; j++) { String logLine = generateLogLine(); PutRecordRequest request = new PutRecordRequest().withStreamName(streamName) .withPartitionKey(PARTITION_KEY) .withData(ByteBuffer.wrap(logLine.getBytes(StandardCharsets.UTF_8))); PutRecordResult result = client.putRecord(request); System.out.println( String.format("Wrote to shard %s as %s", result.getShardId(), result.getSequenceNumber())); } recordsLeft -= numToGenerate; if (recordsLeft > 0) { Thread.sleep(1000L); } } }
From source file:com.grantingersoll.opengrok.analysis.csharp.TestCSharpSymbolTokenizer.java
@Test public void test() throws Exception { String input;//from w ww . j av a 2s . c o m try (InputStream stream = TestCSharpSymbolTokenizer.class.getResourceAsStream("Sample.cs"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { "System", //// using System; //// "MyNamespace", //// namespace MyNamespace //// { //// /// <summary> //// /// summary //// /// </summary> "Tag", //// [Tag] "TopClass", //// class TopClass { "M1", //// public int M1() { } //// "M2", //// public static void M2() { //// //public static int MERR() {} //// } //// //// /// <summary> //// /// sum //// /// </summary> "M3", //// public void M3() //// { //// /* hi //// public static int MERR() { //// } //// */ //// } //// "Tag", //// [Tag] "T", "M4", "T", "T", "p", "T", //// private T M4<T>(T p) where T : new() //// { //// } //// "InnerClass", //// public class InnerClass //// { "M5", "x", //// private string M5(int x) { //// return null; //// } //// } //// //// { //// //// } //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:ee.ria.xroad.common.messagelog.archive.LinkingInfoBuilder.java
void addNextFile(String fileName, byte[] fileBytes) { String combinedDigests = lastDigest + hexDigest(fileBytes); String currentDigest = hexDigest(combinedDigests.getBytes(StandardCharsets.UTF_8)); digestsForFiles.add(new DigestEntry(currentDigest, fileName)); lastDigest = currentDigest;/*from w w w . ja v a 2s.c om*/ }
From source file:com.ibm.streamsx.rest.StreamsConnection.java
/** * Connection to IBM Streams//w w w. j ava 2 s . c o m * * @param userName * String representing the userName to connect to the instance * @param authToken * String representing the password to connect to the instance * @param url * String representing the root url to the REST API, for example: * https:server:port/streams/rest */ protected StreamsConnection(String userName, String authToken, String url) { this.userName = userName; String apiCredentials = userName + ":" + authToken; apiKey = "Basic " + DatatypeConverter.printBase64Binary(apiCredentials.getBytes(StandardCharsets.UTF_8)); executor = Executor.newInstance(); setStreamsRESTURL(url); }
From source file:com.haulmont.cuba.core.app.filestorage.amazon.AmazonS3FileStorageTest.java
@Test public void testWithExtension() throws Exception { fileStorageAPI.saveFile(fileDescr, FILE_CONTENT.getBytes()); InputStream inputStream = fileStorageAPI.openStream(fileDescr); Assert.assertEquals(FILE_CONTENT, IOUtils.toString(inputStream, StandardCharsets.UTF_8)); boolean fileExists = fileStorageAPI.fileExists(fileDescr); Assert.assertTrue(fileExists);// w ww. ja v a 2 s . co m fileStorageAPI.removeFile(fileDescr); }
From source file:net.data.technology.jraft.extensions.http.HttpRpcClient.java
@Override public CompletableFuture<RaftResponseMessage> send(RaftRequestMessage request) { CompletableFuture<RaftResponseMessage> future = new CompletableFuture<RaftResponseMessage>(); String payload = this.gson.toJson(request); HttpPost postRequest = new HttpPost(this.serverUrl); postRequest.setEntity(new StringEntity(payload, StandardCharsets.UTF_8)); this.httpClient.execute(postRequest, new FutureCallback<HttpResponse>() { @Override// w ww . j ava 2 s . c om public void completed(HttpResponse result) { if (result.getStatusLine().getStatusCode() != 200) { logger.info("receive an response error code " + String.valueOf(result.getStatusLine().getStatusCode()) + " from server"); future.completeExceptionally(new IOException("Service Error")); } try { InputStreamReader reader = new InputStreamReader(result.getEntity().getContent()); RaftResponseMessage response = gson.fromJson(reader, RaftResponseMessage.class); future.complete(response); } catch (Throwable error) { logger.info("fails to parse the response from server due to errors", error); future.completeExceptionally(error); } } @Override public void failed(Exception ex) { future.completeExceptionally(ex); } @Override public void cancelled() { future.completeExceptionally(new IOException("request cancelled")); } }); return future; }
From source file:com.grantingersoll.opengrok.analysis.tcl.TestTclSymbolTokenizer.java
@Test public void test() throws Exception { String input;/*from w w w.j ava 2 s . c o m*/ try (InputStream stream = TestTclSymbolTokenizer.class.getResourceAsStream("test.tcl"); 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 //// # //// "printHelloWorld", //// proc printHelloWorld {} { //// puts "Hello world" //// } //// "viewSource", "f", //// proc viewSource { f } { "filesVisited", "EB", //// global filesVisited EB "EB", "curFile", "f", //// set EB(curFile) $f "filesVisited", "f", //// lappend filesVisited $f //// //// # change window title to show the current file "wt", "title", "eb", //// set wt [wm title .eb] "first", "wt", //// if { [string first : $wt] != -1 } { "idx", "first", "wt", //// set idx [string first : $wt] "base", "range", "wt", "idx", //// set base [string range $wt 0 $idx] "wtn", "base", "f", //// set wtn [concat $base $f] //// } else { "wtn", "wt", "f", //// set wtn [concat ${wt}: $f] //// } "title", "eb", "wtn", //// wm title .eb $wtn "eb", "f", "t", "config", "state", "normal", //// .eb.f.t config -state normal "eb", "f", "t", "delete", "end", //// .eb.f.t delete 1.0 end "f", "in", //// if [catch {open $f} in] { "eb", "f", "t", "insert", "end", "in", //// .eb.f.t insert end $in //// } else { "eb", "f", "t", "insert", "end", "in", //// .eb.f.t insert end [read $in] "in", //// close $in //// } "eb", "f", "t", "config", "state", "normal", //// .eb.f.t config -state normal "eb", "buttons", "config", "command", "applySource", "f", //// .eb.buttons.apply config -command [list applySource $f] //// } }; assertAnalyzesTo(analyzer, input, output); }
From source file:org.ulyssis.ipp.publisher.FileOutput.java
@Override public void outputScore(Score score) { Path tmpFile = null;//from ww w . jav a2 s .c om try { if (tmpDir.isPresent()) { tmpFile = Files.createTempFile(tmpDir.get(), "score-", ".json", PosixFilePermissions.asFileAttribute(defaultPerms)); } else { tmpFile = Files.createTempFile("score-", ".json", PosixFilePermissions.asFileAttribute(defaultPerms)); } BufferedWriter writer = Files.newBufferedWriter(tmpFile, StandardCharsets.UTF_8); Serialization.getJsonMapper().writer(new DefaultPrettyPrinter()).writeValue(writer, score); Files.move(tmpFile, filePath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { LOG.error("Error writing score to file!", e); } finally { try { if (tmpFile != null) Files.deleteIfExists(tmpFile); } catch (IOException ignored) { } } }