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:ch.algotrader.config.spring.ConfigLoader.java
static void loadResource(final Map<String, String> paramMap, final Resource resource) throws IOException { try (InputStream inputStream = resource.getInputStream()) { Properties props = new Properties(); props.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); for (Map.Entry<Object, Object> entry : props.entrySet()) { String paramName = (String) entry.getKey(); String paramValue = (String) entry.getValue(); if (StringUtils.isNotBlank(paramName)) { paramMap.put(paramName, paramValue); }//from w ww . ja v a 2 s . c o m } } }
From source file:Main.java
/** ask transformer to use UTF-8 * @param transformer will encode output as UTF-8 *//*w w w . j a v a 2 s . co m*/ public static void setUtfEncoding(final Transformer transformer) { transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name()); }
From source file:Main.java
public static Node asDOMNode(String xml) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); return doc.getFirstChild(); }
From source file:com.github.tddts.jet.util.Util.java
/** * Load content of given resource as String. * * @param resourceName path to resource//from w w w.j a v a 2 s. co m * @return file content as String * @throws FileLoadingException in case of any errors */ public static String loadContent(String resourceName) throws FileLoadingException { try (InputStream inputStream = Util.class.getResourceAsStream(resourceName)) { if (inputStream == null) { throw new FileLoadingException("Not found: " + resourceName); } return new String(IOUtils.toByteArray(inputStream), StandardCharsets.UTF_8); } catch (Exception e) { throw new FileLoadingException(e); } }
From source file:co.rsk.net.discovery.message.PingPeerMessage.java
public static PingPeerMessage create(String host, int port, String check, ECKey privKey) { /* RLP Encode data */ byte[] rlpIp = RLP.encodeElement(host.getBytes(StandardCharsets.UTF_8)); byte[] tmpPort = longToBytes(port); byte[] rlpPort = RLP.encodeElement(stripLeadingZeroes(tmpPort)); byte[] rlpIpTo = RLP.encodeElement(host.getBytes(StandardCharsets.UTF_8)); byte[] tmpPortTo = longToBytes(port); byte[] rlpPortTo = RLP.encodeElement(stripLeadingZeroes(tmpPortTo)); byte[] rlpCheck = RLP.encodeElement(check.getBytes(StandardCharsets.UTF_8)); byte[] type = new byte[] { (byte) DiscoveryMessageType.PING.getTypeValue() }; byte[] rlpFromList = RLP.encodeList(rlpIp, rlpPort, rlpPort); byte[] rlpToList = RLP.encodeList(rlpIpTo, rlpPortTo, rlpPortTo); byte[] data = RLP.encodeList(rlpFromList, rlpToList, rlpCheck); PingPeerMessage message = new PingPeerMessage(); message.encode(type, data, privKey); message.messageId = check;/*from w w w. java2s . com*/ message.host = host; message.port = port; return message; }
From source file:co.rsk.net.discovery.message.PongPeerMessage.java
public static PongPeerMessage create(String host, int port, String check, ECKey privKey) { /* RLP Encode data */ byte[] rlpIp = RLP.encodeElement(host.getBytes(StandardCharsets.UTF_8)); byte[] tmpPort = longToBytes(port); byte[] rlpPort = RLP.encodeElement(stripLeadingZeroes(tmpPort)); byte[] rlpIpTo = RLP.encodeElement(host.getBytes(StandardCharsets.UTF_8)); byte[] tmpPortTo = longToBytes(port); byte[] rlpPortTo = RLP.encodeElement(stripLeadingZeroes(tmpPortTo)); byte[] rlpCheck = RLP.encodeElement(check.getBytes(StandardCharsets.UTF_8)); byte[] type = new byte[] { (byte) DiscoveryMessageType.PONG.getTypeValue() }; byte[] rlpFromList = RLP.encodeList(rlpIp, rlpPort, rlpPort); byte[] rlpToList = RLP.encodeList(rlpIpTo, rlpPortTo, rlpPortTo); byte[] data = RLP.encodeList(rlpFromList, rlpToList, rlpCheck); PongPeerMessage message = new PongPeerMessage(); message.encode(type, data, privKey); message.messageId = check;/*from w ww.j a va 2s. c o m*/ message.host = host; message.port = port; return message; }
From source file:Main.java
/** * Load lines of strings from a file/*from www . j a v a 2s.c o m*/ * * @param path the path to the file * @param fileName the file name * @return an list of string lines */ public static List<String> loadFromFile(File path, String fileName) { ArrayList<String> arrayList = new ArrayList<>(); if (path.exists()) { File file = new File(path, fileName); BufferedReader bufferedReader = null; InputStreamReader isr = null; FileInputStream fis = null; try { fis = new FileInputStream(file); isr = new InputStreamReader(fis, StandardCharsets.UTF_8); bufferedReader = new BufferedReader(isr); String line; while ((line = bufferedReader.readLine()) != null) { arrayList.add(line); } return arrayList; } catch (IOException ignored) { } finally { if (isr != null) { try { isr.close(); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } } if (fis != null) { try { fis.close(); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } } } } return null; }
From source file:io.servicecomb.foundation.common.net.URIEndpointObject.java
public static Map<String, List<String>> splitQuery(URI uri) { final Map<String, List<String>> queryPairs = new LinkedHashMap<String, List<String>>(); List<NameValuePair> pairs = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8.name()); for (NameValuePair pair : pairs) { List<String> list = queryPairs.computeIfAbsent(pair.getName(), name -> { return new ArrayList<>(); });/*from w w w . j a va2 s . co m*/ list.add(pair.getValue()); } return queryPairs; }
From source file:com.amazonaws.codepipeline.jenkinsplugin.ExtractionTools.java
private static void extractZip(final File source, final File destination) throws IOException { try (final ZipFile zipFile = new ZipFile(source, StandardCharsets.UTF_8.name(), true)) { extractZipFile(destination, zipFile); }/*from w ww. j av a 2 s . com*/ }
From source file:com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileUtils.java
private static File writeToFile(final File file, final String contents, final boolean overwrite) throws IOException { if (file == null) { return null; }//www .j a v a2s. co m if (overwrite && file.exists()) { file.delete(); } if (file.exists()) { logger.info(String.format("%s exists and not being overwritten", file.getAbsolutePath())); } else { FileUtils.write(file, contents, StandardCharsets.UTF_8); } return file; }