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.moquette.spi.impl.security.DBAuthenticatorTest.java
@Before public void setup() throws ClassNotFoundException, SQLException, NoSuchAlgorithmException { Class.forName(ORG_H2_DRIVER); this.connection = DriverManager.getConnection(JDBC_H2_MEM_TEST); Statement statement = this.connection.createStatement(); try {/*from ww w .j a v a 2 s .c o m*/ statement.execute("DROP TABLE ACCOUNT"); } catch (SQLException sqle) { LOG.info("Table not found, not dropping", sqle); } MessageDigest digest = MessageDigest.getInstance(SHA_256); String hash = new String(Hex.encodeHex(digest.digest("password".getBytes(StandardCharsets.UTF_8)))); try { if (statement.execute("CREATE TABLE ACCOUNT ( LOGIN VARCHAR(64), PASSWORD VARCHAR(256))")) { throw new SQLException("can't create USER table"); } if (statement.execute("INSERT INTO ACCOUNT ( LOGIN , PASSWORD ) VALUES ('dbuser', '" + hash + "')")) { throw new SQLException("can't insert in USER table"); } } catch (SQLException sqle) { LOG.error("Table not created, not inserted", sqle); return; } LOG.info("Table User created"); statement.close(); }
From source file:com.greensopinion.finance.services.encryption.Encryptor.java
public String decrypt(String data) { if (data == null) { return null; }//from w w w.j av a 2 s . c o m byte[] decodedBytes = Hex.decode(data); byte[] decryptedBytes = encryptor.decrypt(decodedBytes); return new String(decryptedBytes, StandardCharsets.UTF_8); }
From source file:au.org.emii.geoserver.extensions.filters.layer.data.io.FilterConfigurationReaderTest.java
@Test public void readTest() throws ParserConfigurationException, SAXException, IOException { InputStream stream = null;/*from w w w . j ava 2s . co m*/ FilterConfigurationReader reader = new FilterConfigurationReader(""); try { stream = new ByteArrayInputStream(XML.getBytes(StandardCharsets.UTF_8)); FilterConfiguration filterConfiguration = reader.read(stream); assertEquals(4, filterConfiguration.getFilters().size()); assertEquals("integer", filterConfiguration.getFilters().get(0).getType()); assertEquals(Boolean.FALSE, filterConfiguration.getFilters().get(0).getVisualised()); assertEquals(Boolean.TRUE, filterConfiguration.getFilters().get(1).getVisualised()); assertEquals("This", filterConfiguration.getFilters().get(2).getLabel()); assertEquals("deployment_name", filterConfiguration.getFilters().get(3).getName()); assertEquals(Boolean.TRUE, filterConfiguration.getFilters().get(3).getExcludedFromDownload()); } finally { IOUtils.closeQuietly(stream); } }
From source file:org.apache.gobblin.HttpTestUtils.java
public static void assertEqual(RequestBuilder actual, RequestBuilder expect) throws IOException { // Check entity HttpEntity actualEntity = actual.getEntity(); HttpEntity expectedEntity = expect.getEntity(); if (actualEntity == null) { Assert.assertTrue(expectedEntity == null); } else {//from w w w . j ava2s.co m Assert.assertEquals(actualEntity.getContentLength(), expectedEntity.getContentLength()); String actualContent = IOUtils.toString(actualEntity.getContent(), StandardCharsets.UTF_8); String expectedContent = IOUtils.toString(expectedEntity.getContent(), StandardCharsets.UTF_8); Assert.assertEquals(actualContent, expectedContent); } // Check request HttpUriRequest actualRequest = actual.build(); HttpUriRequest expectedRequest = expect.build(); Assert.assertEquals(actualRequest.getMethod(), expectedRequest.getMethod()); Assert.assertEquals(actualRequest.getURI().toString(), expectedRequest.getURI().toString()); Header[] actualHeaders = actualRequest.getAllHeaders(); Header[] expectedHeaders = expectedRequest.getAllHeaders(); Assert.assertEquals(actualHeaders.length, expectedHeaders.length); for (int i = 0; i < actualHeaders.length; i++) { Assert.assertEquals(actualHeaders[i].toString(), expectedHeaders[i].toString()); } }
From source file:org.ligoj.app.http.security.RestAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) { final String userpassword = StringUtils.defaultString(authentication.getCredentials().toString(), ""); final String userName = StringUtils.lowerCase(authentication.getPrincipal().toString()); // First get the cookie final HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()); final HttpPost httpPost = new HttpPost(getSsoPostUrl()); // Do the POST try (CloseableHttpClient httpClient = clientBuilder.build()) { final String content = String.format(getSsoPostContent(), userName, userpassword); httpPost.setEntity(new StringEntity(content, StandardCharsets.UTF_8)); httpPost.setHeader("Content-Type", "application/json"); final HttpResponse httpResponse = httpClient.execute(httpPost); if (HttpStatus.SC_NO_CONTENT == httpResponse.getStatusLine().getStatusCode()) { // Succeed authentication, save the cookies data inside the authentication return newAuthentication(userName, userpassword, authentication, httpResponse); }//from w ww . j a v a 2s.c o m log.info("Failed authentication of {}[{}] : {}", userName, userpassword.length(), httpResponse.getStatusLine().getStatusCode()); httpResponse.getEntity().getContent().close(); } catch (final IOException e) { log.warn("Remote SSO server is not available", e); } throw new BadCredentialsException("Invalid user or password"); }
From source file:at.ac.tuwien.dsg.depic.dataassetfunctionmanagement.store.MySqlDataAssetStore.java
public void storeDataAsset(DataAsset da) { try {//from www .j av a 2 s .c o m String daXML = JAXBUtils.marshal(da, DataAsset.class); Logger.getLogger(MySqlDataAssetStore.class.getName()).log(Level.INFO, "Prepare to Store: " + daXML); InputStream daStream = new ByteArrayInputStream(daXML.getBytes(StandardCharsets.UTF_8)); List<InputStream> listOfInputStreams = new ArrayList<InputStream>(); listOfInputStreams.add(daStream); String sql = "INSERT INTO DataAsset (dataAssetID, dataPartitionID, data) VALUES ('" + da.getDataAssetID() + "'," + da.getPartition() + ",?)"; connectionManager.ExecuteUpdateBlob(sql, listOfInputStreams); } catch (Exception ex) { Logger.getLogger(MySqlDataAssetStore.class.getName()).log(Level.SEVERE, ex.toString()); } }
From source file:org.dimitrovchi.conf.service.demo.DemoService.java
public DemoService(P parameters) throws IOException { super(parameters); this.httpServer = HttpServer.create(new InetSocketAddress(parameters.host(), parameters.port()), 0); this.httpServer.setExecutor(executor); this.httpServer.createContext("/", new HttpHandler() { @Override// w ww.ja va2 s. c om public void handle(HttpExchange he) throws IOException { he.getResponseHeaders().add("Content-Type", "text/plain; charset=utf-8"); final byte[] message = "hello!".getBytes(StandardCharsets.UTF_8); he.sendResponseHeaders(HttpURLConnection.HTTP_OK, message.length); he.getResponseBody().write(message); } }); log.info(ServiceParameterUtils.reflectToString("demoService", parameters)); }
From source file:com.ericsson.gerrit.plugins.highavailability.forwarder.rest.HttpSession.java
HttpResult post(String endpoint, String content) throws IOException { HttpPost post = new HttpPost(getPeerInfo().getDirectUrl() + endpoint); if (!Strings.isNullOrEmpty(content)) { post.addHeader("Content-Type", MediaType.JSON_UTF_8.toString()); post.setEntity(new StringEntity(content, StandardCharsets.UTF_8)); }// w w w . j av a 2 s .c om return httpClient.execute(post, new HttpResponseHandler()); }
From source file:eu.falcon.fusion.TestTimeSeries.java
@Test public void testtimeseries() { BufferedReader br1 = null;/* ww w .j a va 2 s.c o m*/ String line = ""; String cvsSplitBy = ","; try { br1 = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/dates.csv"))); while ((line = br1.readLine()) != null) { // use comma as separator String[] date = line.split(cvsSplitBy); System.out.println(date[0]); InputStream inputStream; String jsonldToSaveToMongoAndFuseki = generateMeasurement("F284211", date[0]); System.out.println("jsonldToSaveToMongoAndFuseki" + jsonldToSaveToMongoAndFuseki); inputStream = new ByteArrayInputStream( jsonldToSaveToMongoAndFuseki.getBytes(StandardCharsets.UTF_8)); //inputStream = new FileInputStream("/home/eleni/NetBeansProjects/falcon-data-management/fusion/src/main/resources/sensorData.json"); String serviceURI = "http://localhost:3030/datetimeseries/data"; //DatasetAccessorFactory factory = null; DatasetAccessor accessor; accessor = DatasetAccessorFactory.createHTTP(serviceURI); Model m = ModelFactory.createDefaultModel(); String base = "http://test-projects.com/"; m.read(inputStream, base, "JSON-LD"); //accessor.putModel(m); accessor.add(m); inputStream.close(); DBObject dbObject = (DBObject) JSON.parse(jsonldToSaveToMongoAndFuseki); } br1.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } }
From source file:com.thoughtworks.go.websocket.MessageEncoding.java
public static byte[] encodeMessage(Message msg) { String encode = gson.toJson(msg); try {// ww w . jav a 2 s. c o m try (ByteArrayOutputStream bytes = new ByteArrayOutputStream()) { try (GZIPOutputStream out = new GZIPOutputStream(bytes)) { out.write(encode.getBytes(StandardCharsets.UTF_8)); out.finish(); } return bytes.toByteArray(); } } catch (IOException e) { throw bomb(e); } }