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:cz.muni.fi.webmias.TeXConverter.java
/** * Converts TeX formula to MathML using LaTeXML through a web service. * * @param query String containing one or more keywords and TeX formulae * (formulae enclosed in $ or $$).//from www. j a va2 s . c o m * @return String containing formulae converted to MathML that replaced * original TeX forms. Non math tokens are connected at the end. */ public static String convertTexLatexML(String query) { query = query.replaceAll("\\$\\$", "\\$"); if (query.matches(".*\\$.+\\$.*")) { try { HttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost(LATEX_TO_XHTML_CONVERSION_WS_URL); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<>(1); params.add(new BasicNameValuePair("code", query)); httppost.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8)); // Execute and get the response. HttpResponse response = httpclient.execute(httppost); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity resEntity = response.getEntity(); if (resEntity != null) { try (InputStream responseContents = resEntity.getContent()) { DocumentBuilder dBuilder = MIaSUtils.prepareDocumentBuilder(); org.w3c.dom.Document doc = dBuilder.parse(responseContents); NodeList ps = doc.getElementsByTagName("p"); String convertedMath = ""; for (int k = 0; k < ps.getLength(); k++) { Node p = ps.item(k); NodeList pContents = p.getChildNodes(); for (int j = 0; j < pContents.getLength(); j++) { Node pContent = pContents.item(j); if (pContent instanceof Text) { convertedMath += pContent.getNodeValue() + "\n"; } else { TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(pContent), new StreamResult(buffer)); convertedMath += buffer.toString() + "\n"; } } } return convertedMath; } } } } catch (TransformerException | SAXException | ParserConfigurationException | IOException ex) { Logger.getLogger(ProcessServlet.class.getName()).log(Level.SEVERE, null, ex); } } return query; }
From source file:ai.susi.json.JsonStreamReader.java
public void run() { BufferedReader br = null;/* ww w . j a v a2 s .c om*/ try { String line; br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); while ((line = br.readLine()) != null) { try { JSONObject json = new JSONObject(line); this.jsonline.put(new WrapperJsonFactory(json)); } catch (Throwable e) { Log.getLog().warn(e); } } } catch (IOException e) { Log.getLog().warn(e); } finally { try { if (br != null) br.close(); } catch (IOException e) { Log.getLog().warn(e); } } for (int i = 0; i < this.concurrency; i++) { try { this.jsonline.put(JsonReader.POISON_JSON_MAP); } catch (InterruptedException e) { } } }
From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java
public synchronized static String getB64CaCrt() throws IOException { if (StringUtils.isBlank(b64CaCrt)) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CA_CRT_FILE); b64CaCrt = StreamUtil.stream2Bytes(is, StandardCharsets.UTF_8); b64CaCrt = StringUtils.removeStart(b64CaCrt, BEGIN_CERT); b64CaCrt = StringUtils.removeEnd(b64CaCrt, END_CERT); }/*from ww w . j a v a 2 s . co m*/ return b64CaCrt; }
From source file:com.grantingersoll.opengrok.analysis.javascript.TestJavaScriptSymbolTokenizer.java
@Test public void test() throws Exception { String input;/*from w w w . j a v a 2 s . com*/ try (InputStream stream = TestJavaScriptSymbolTokenizer.class.getResourceAsStream("function.js"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// /* //// * Sample js program //// */ //// "date", //// var date = new Date(96, 11, 25); //// //reference "ref", "date", //// var ref = date; //// "ref", "setDate", //// ref.setDate(21); //// "date", "getDate", //// date.getDate(); //21 //// //// // The same is true when objects and arrays are passed to functions. //// // The following function adds a value to each element of an array. //// // A reference to the array is passed to the function, not a copy of the array. //// // Therefore, the function can change the contents of the array through //// // the reference, and those changes will be visible when the function returns. "main", "totals", "x", //// function main(totals, x) //// { "totals", "totals", "x", //// totals[0] = totals[0] + x; "totals", "totals", "x", //// totals[1] = totals[1] + x; "totals", "totals", "x", //// totals[2] = totals[2] + x; //// } //// "numberliteral", //// var numberliteral = 0x4f; //// "date", "ref", //// (date == ref) // Evaluates to true //// "ndate", //// var ndate= new Date(96, 11, 25); "sameobjectasndate", //// var sameobjectasndate = new Date(96, 11, 25); //// "ndate", "sameobjectasndate", //// (ndate != sameobjectasndate) // true ! //// //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:hudson.util.io.ZipArchiver.java
@Override public void visitSymlink(final File f, final String target, final String relativePath) throws IOException { int mode = IOUtils.lmode(f); ZipArchiveEntry zae = new ZipArchiveEntry(relativePath); if (mode != -1) { zae.setUnixMode(mode);/* ww w . ja v a2 s .com*/ } zae.setTime(f.lastModified()); zip.putArchiveEntry(zae); zip.write(target.getBytes(StandardCharsets.UTF_8), 0, target.length()); zip.closeArchiveEntry(); entriesWritten++; }
From source file:mtsar.resources.AnswerResource.java
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response postAnswersCSV(@Context UriInfo uriInfo, @FormDataParam("file") InputStream stream) throws IOException { try (final Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { try (final CSVParser csv = new CSVParser(reader, AnswerCSV.FORMAT)) { answerDAO.insert(AnswerCSV.parse(stage, csv)); }/*www. ja v a 2s .co m*/ } answerDAO.resetSequence(); return Response.seeOther(getAnswersURI(uriInfo)).build(); }
From source file:com.blackducksoftware.integration.hub.detect.detector.go.GoVendorExtractor.java
public Extraction extract(final File directory, final File vendorJsonFile) { try {//from w ww. ja v a 2 s .c o m final GoVendorJsonParser vendorJsonParser = new GoVendorJsonParser(externalIdFactory); final String vendorJsonContents = FileUtils.readFileToString(vendorJsonFile, StandardCharsets.UTF_8); logger.debug(vendorJsonContents); final DependencyGraph dependencyGraph = vendorJsonParser.parseVendorJson(gson, vendorJsonContents); final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString()); final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_VENDOR, directory.toString(), externalId, dependencyGraph).build(); return new Extraction.Builder().success(codeLocation).build(); } catch (final Exception e) { return new Extraction.Builder().exception(e).build(); } }
From source file:org.ligoj.app.plugin.prov.google.ProvGoogleResourceTest.java
@BeforeEach public void prepareData() throws IOException { persistSystemEntities();/*from ww w . ja va2 s .co m*/ persistEntities("csv", new Class[] { Node.class, Project.class, Subscription.class, ProvLocation.class, ProvQuote.class, ProvStorageType.class, ProvInstancePriceTerm.class, ProvInstanceType.class, ProvInstancePrice.class, ProvQuoteInstance.class, ProvQuoteStorage.class }, StandardCharsets.UTF_8.name()); subscription = getSubscription("gStack", ProvGoogleResource.SERVICE_KEY); }
From source file:org.graylog2.inputs.twitter.TwitterCodec.java
@Nullable @Override//w w w . ja v a2s .co m public Message decode(@Nonnull final RawMessage rawMessage) { final Status status; try { status = TwitterObjectFactory.createStatus(new String(rawMessage.getPayload(), StandardCharsets.UTF_8)); } catch (TwitterException e) { LOG.warn("Error while decoding raw message", e); return null; } return createMessageFromStatus(status); }
From source file:com.grantingersoll.opengrok.analysis.golang.TestGolangSymbolTokenizer.java
@Test public void test() throws Exception { String input;//from ww w . j ava 2 s . c o m try (InputStream stream = TestGolangSymbolTokenizer.class.getResourceAsStream("stats.go"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// //// From https://go.googlesource.com/go/+/master/test/bench/garbage/stats.go //// //// // Copyright 2010 The Go Authors. All rights reserved. //// // Use of this source code is governed by a BSD-style //// // license that can be found in the LICENSE file. "main", //// package main //// import ( //// "fmt" //// "runtime" //// "sort" //// "time" //// ) "gcstats", "name", "string", "n", "int", "t", "time", "Duration", //// func gcstats(name string, n int, t time.Duration) { "st", "new", "runtime", "MemStats", //// st := new(runtime.MemStats) "runtime", "ReadMemStats", "st", //// runtime.ReadMemStats(st) "nprocs", "runtime", "GOMAXPROCS", //// nprocs := runtime.GOMAXPROCS(-1) "cpus", //// cpus := "" "nprocs", //// if nprocs != 1 { "cpus", "fmt", "Sprintf", "nprocs", //// cpus = fmt.Sprintf("-%d", nprocs) //// } "fmt", "Printf", "name", "cpus", "st", "Alloc", "st", "TotalAlloc", "st", "Sys", "st", "NextGC", "st", "Mallocs", //// fmt.Printf("garbage.%sMem%s Alloc=%d/%d Heap=%d NextGC=%d Mallocs=%d\n", name, cpus, st.Alloc, st.TotalAlloc, st.Sys, st.NextGC, st.Mallocs) "fmt", "Printf", "name", "cpus", "n", "t", "Nanoseconds", "int64", "n", //// fmt.Printf("garbage.%s%s %d %d ns/op\n", name, cpus, n, t.Nanoseconds()/int64(n)) "fmt", "Printf", "name", "cpus", "st", "PauseNs", "st", "NumGC", "uint32", "len", "st", "PauseNs", //// fmt.Printf("garbage.%sLastPause%s 1 %d ns/op\n", name, cpus, st.PauseNs[(st.NumGC-1)%uint32(len(st.PauseNs))]) "fmt", "Printf", "name", "cpus", "st", "NumGC", "int64", "st", "PauseTotalNs", "int64", "st", "NumGC", //// fmt.Printf("garbage.%sPause%s %d %d ns/op\n", name, cpus, st.NumGC, int64(st.PauseTotalNs)/int64(st.NumGC)) "nn", "int", "st", "NumGC", //// nn := int(st.NumGC) "nn", "len", "st", "PauseNs", //// if nn >= len(st.PauseNs) { "nn", "len", "st", "PauseNs", //// nn = len(st.PauseNs) //// } "t1", "t2", "t3", "t4", "t5", "tukey5", "st", "PauseNs", "nn", //// t1, t2, t3, t4, t5 := tukey5(st.PauseNs[0:nn]) "fmt", "Printf", "name", "cpus", "t1", "t2", "t3", "t4", "t5", //// fmt.Printf("garbage.%sPause5%s: %d %d %d %d %d\n", name, cpus, t1, t2, t3, t4, t5) //// // fmt.Printf("garbage.%sScan: %v\n", name, st.ScanDist) //// } "T", "uint64", //// type T []uint64 "t", "T", "Len", "int", "len", "t", //// func (t T) Len() int { return len(t) } "t", "T", "Swap", "i", "j", "int", "t", "i", "t", "j", "t", "j", "t", "i", //// func (t T) Swap(i, j int) { t[i], t[j] = t[j], t[i] } "t", "T", "Less", "i", "j", "int", "bool", "t", "i", "t", "j", //// func (t T) Less(i, j int) bool { return t[i] < t[j] } "tukey5", "raw", "uint64", "lo", "q1", "q2", "q3", "hi", "uint64", //// func tukey5(raw []uint64) (lo, q1, q2, q3, hi uint64) { "x", "make", "T", "len", "raw", //// x := make(T, len(raw)) "copy", "x", "raw", //// copy(x, raw) "sort", "Sort", "T", "x", //// sort.Sort(T(x)) "lo", "x", //// lo = x[0] "q1", "x", "len", "x", //// q1 = x[len(x)/4] "q2", "x", "len", "x", //// q2 = x[len(x)/2] "q3", "x", "len", "x", //// q3 = x[len(x)*3/4] "hi", "x", "len", "x", //// hi = x[len(x)-1] //// return //// } }; //// assertAnalyzesTo(analyzer, input, output); }