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:io.github.swagger2markup.internal.component.DefinitionComponentTest.java
@Test public void testDefinitionComponent() throws URISyntaxException { //Given//from w w w . ja v a 2 s . co m Path file = Paths.get(DefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build(); Swagger swagger = converter.getContext().getSwagger(); Model petModel = swagger.getDefinitions().get("Pet"); Swagger2MarkupConverter.Context context = converter.getContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); //When markupDocBuilder = new DefinitionComponent(context, new DefinitionDocumentResolverFromDefinition(context)) .apply(markupDocBuilder, DefinitionComponent.parameters("Pet", petModel, 2)); markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8); //Then Path expectedFile = getExpectedFile(COMPONENT_NAME); DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME)); }
From source file:hudson.plugins.jetty.security.Password.java
public static String deobfuscate(String s) { if (s.startsWith(__OBFUSCATE)) s = s.substring(__OBFUSCATE.length()); if (StringUtils.isEmpty(s)) return ""; byte[] b = new byte[s.length() / 2]; int l = 0;//from w ww.j a v a2 s.co m for (int i = 0; i < s.length(); i += 4) { String x = s.substring(i, i + 4); int i0 = Integer.parseInt(x, 36); int i1 = (i0 / 256); int i2 = (i0 % 256); b[l++] = (byte) ((i1 + i2 - 254) / 2); } return new String(b, 0, l, StandardCharsets.UTF_8); }
From source file:com.grantingersoll.opengrok.analysis.cxx.TestCxxSymbolTokenizer.java
@Test public void test() throws Exception { String input;// w w w .j a v a 2s.co m try (InputStream stream = TestCxxSymbolTokenizer.class.getResourceAsStream("sample.cxx"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// // compile me with g++ //// /* this is sample comment } */ "string", //// #include <string> "vector", //// #include <vector> "iostream", //// #include <iostream> //// "TEST", "x", "x", //// #define TEST(x) (x) //// "SomeClass", //// class SomeClass { //// public: "SomeClass", //// SomeClass() /* I'm constructor */ "attr_", //// : attr_(0) //// { "std", "cout", "std", "endl", //// std::cout << "Hello" << std::endl; //// } //// "SomeClass", //// ~SomeClass() // destructor //// { "std", "cout", "std", "endl", //// std::cout << "Bye" << std::endl; //// } //// "MemberFunc", "a", "b", //// int MemberFunc(int a, int b) const { //// // some member function "a", "b", //// return a + b; //// } //// //// int operator++(int) { "attr_", //// return attr_++; //// } //// "T", //// template<typename T> "size_t", "TemplateMember", "std", "vector", "T", "v", //// size_t TemplateMember(std::vector<T>& v) { "v", "size", //// return v.size(); //// } //// //// private: "attr_", //// int attr_; //// }; //// "ns1", //// namespace ns1 { //// "NamespacedClass", //// class NamespacedClass { //// public: "SomeFunc", "std", "string", "arg", //// static void SomeFunc(const std::string& arg) { "std", "cout", "arg", //// std::cout << arg; //// } //// }; //// "ns2", //// namespace ns2 { //// "foo", "a", "b", //// int foo(int a, int b) { "SomeClass", "t", //// SomeClass t; "t", "MemberFunc", "TEST", "a", "TEST", "b", //// return t.MemberFunc(TEST(a), TEST(b)); //// } //// //// } //// } //// "bar", "x", //// int bar(int x /* } */) //// { //// // another function "d", //// int d; "f", //// int f; "std", "cout", "TEST", "std", "endl", //// std::cout << TEST("test { message|$#@$!!#") << std::endl; "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[]) { "SomeClass", "c", //// SomeClass c; "res", //// int res; "std", "cout", "std", "endl", //// std::cout << "this is just a {sample}}" << std::endl; //// "res", "bar", //// res = bar(20); "std", "cout", "res", "std", "endl", //// std::cout << "result = {" << res << "}" << std::endl; //// "std", "cout", "c", "MemberFunc", "std", "endl", //// std::cout << c.MemberFunc(1, 2) << std::endl; "std", "cout", "c", "std", "endl", //// std::cout << c++ << std::endl; //// //// return 0; } //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:fi.vm.kapa.identification.proxy.vtj.VtjClient.java
public VTJResponse fetchVtjData(Identifier.Types type, String identifier, String issuerDn) throws VtjServiceException { Response response = null;/*from ww w . ja v a 2s . co m*/ try { String issuerEncoded = java.net.URLEncoder.encode(issuerDn, StandardCharsets.UTF_8.toString()); WebTarget webTarget = getClient() .target(vtjClientEndpoint + "/" + identifier + "/" + type + "?issuerDn=" + issuerEncoded); Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); response = invocationBuilder.get(); } catch (Exception e) { logger.error("Vtj connection not established. Service request failed."); throw new VtjServiceException("Vtj connection not established. Service request failed."); } if (response.getStatus() == HttpStatus.OK.value()) { VTJResponse vtjResponse = response.readEntity(VTJResponse.class); if (vtjResponse == null) { logger.debug("VTJ returned no data for user " + identifier); } return vtjResponse; } else { logger.error("Vtj connection error: " + response.getStatus()); throw new VtjServiceException("Vtj connection error: " + response.getStatus()); } }
From source file:com.blackducksoftware.integration.hub.detect.detector.cocoapods.PodlockExtractor.java
public Extraction extract(final File directory, final File podlock) { String podLockText;/*from w ww. j a v a 2s.c o m*/ try { logger.trace(String.format("Reading from the pod lock file %s", podlock.getAbsolutePath())); podLockText = FileUtils.readFileToString(podlock, StandardCharsets.UTF_8); logger.debug(podLockText); logger.trace("Finished reading from the pod lock file."); } catch (final IOException e) { return new Extraction.Builder().exception(e).build(); } DependencyGraph dependencyGraph; try { logger.trace("Attempting to create the dependency graph from the pod lock file."); dependencyGraph = podlockParser.extractDependencyGraph(podLockText); logger.trace("Finished creating the dependency graph from the pod lock file."); } catch (final IOException e) { return new Extraction.Builder().exception(e).build(); } final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.COCOAPODS, directory.toString()); final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.COCOAPODS, directory.toString(), externalId, dependencyGraph).build(); return new Extraction.Builder().success(codeLocation).build(); }
From source file:com.evolveum.midpoint.cli.common.ToolsUtils.java
public static String serializeObject(Object object) throws JAXBException { if (object == null) { return null; }//w w w. ja va 2 s . c o m Marshaller marshaller = JAXB_CONTEXT.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); marshaller.marshal(object, sw); return sw.toString(); }
From source file:com.aqnote.shared.cryptology.cert.loader.CaCertLoader.java
public synchronized static String getB64RootCaCert() throws IOException { if (StringUtils.isBlank(b64RootCaCert)) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CA_Cert_FILE); b64RootCaCert = StreamUtil.stream2Bytes(is, StandardCharsets.UTF_8); b64RootCaCert = StringUtils.removeStart(b64RootCaCert, BEGIN_CERT); b64RootCaCert = StringUtils.removeEnd(b64RootCaCert, END_CERT); }//from w w w.ja v a2 s . c o m return b64RootCaCert; }
From source file:org.wso2.carbon.identity.jwt.client.extension.service.JWTClientUtilTest.java
@Test(description = "Test get response string.") public void testGetResponseString() throws IOException { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null); BasicHttpEntity httpEntity = new BasicHttpEntity(); httpEntity.setContent(new ByteArrayInputStream("test message".getBytes(StandardCharsets.UTF_8.name()))); response.setEntity(httpEntity);/*from www.j av a2 s . c om*/ String result = JWTClientUtil.getResponseString(response); Assert.assertEquals(result, "test message"); }
From source file:org.ligoj.app.http.security.DigestAuthenticationFilter.java
@Override public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) { final String token = request.getParameter("token"); if (token != null) { // Token is the last part of URL // First get the cookie final HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.setDefaultRequestConfig( RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()); // Do the POST try (CloseableHttpClient httpClient = clientBuilder.build()) { final HttpPost httpPost = new HttpPost(getSsoPostUrl()); httpPost.setEntity(new StringEntity(token, StandardCharsets.UTF_8.name())); httpPost.setHeader("Content-Type", "application/json"); final HttpResponse httpResponse = httpClient.execute(httpPost); if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) { return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken( EntityUtils.toString(httpResponse.getEntity()), "N/A", new ArrayList<>())); }//from ww w . java2 s . c o m } catch (final IOException e) { log.warn("Local SSO server is not available", e); } } throw new BadCredentialsException("Invalid user or password"); }
From source file:com.hurence.logisland.processor.hbase.io.TestJsonFullRowSerializer.java
@Test public void testSerializeRegular() throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final RowSerializer rowSerializer = new JsonFullRowSerializer(StandardCharsets.UTF_8, StandardCharsets.UTF_8); rowSerializer.serialize(rowKey, cells, out); final String json = out.toString(StandardCharsets.UTF_8.name()); Assert.assertEquals("{\"row\":\"row1\", \"cells\": [" + "{\"fam\":\"" + FAM1 + "\",\"qual\":\"" + QUAL1 + "\",\"val\":\"" + VAL1 + "\",\"ts\":" + TS1 + "}, " + "{\"fam\":\"" + FAM2 + "\",\"qual\":\"" + QUAL2 + "\",\"val\":\"" + VAL2 + "\",\"ts\":" + TS2 + "}]}", json); }