List of usage examples for java.lang String String
String(byte[] value, byte coder)
From source file:Main.java
public static void main(String[] argv) { byte[] bytes = new byte[] { 65, 66, 67, 68 }; System.out.println(new String(bytes, 5)); }
From source file:Main.java
public static void main(String[] argv) { byte[] bytes = new byte[] { 65, 66, 67, 68 }; System.out.println(new String(bytes, Charset.forName("ASCII"))); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String string = "abc\u5639"; byte[] utf8 = string.getBytes("UTF-8"); string = new String(utf8, "UTF-8"); System.out.println(string);/*from w w w .ja va2 s . c om*/ }
From source file:Main.java
public static void main(String[] argv) { byte[] bytes = new byte[] { 65, 66, 67, 68 }; try {//from w ww .ja v a 2 s. com System.out.println(new String(bytes, "ASCII")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String args[]) { System.out.println("a = " + new String(a, 0)); }
From source file:Main.java
public static void main(String[] args) { Path wiki_path = Paths.get("C:/tutorial/wiki", "wiki.txt"); try {/*from ww w . j a va 2 s.co m*/ byte[] wikiArray = Files.readAllBytes(wiki_path); String wikiString = new String(wikiArray, "ISO-8859-1"); System.out.println(wikiString); } catch (IOException e) { System.out.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String input = "Hello world!"; byte[] uncompressedData = input.getBytes("UTF-8"); byte[] compressedData = compress(uncompressedData, Deflater.BEST_COMPRESSION, false); byte[] decompressedData = decompress(compressedData, false); String output = new String(decompressedData, "UTF-8"); System.out.println("Uncompressed data length: " + uncompressedData.length); System.out.println("Compressed data length: " + compressedData.length); System.out.println("Decompressed data length: " + decompressedData.length); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede"); keyGenerator.init(168);//from w w w .j a v a 2s. co m Key key = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] ciphertext = cipher.doFinal("text".getBytes("UTF8")); for (int i = 0; i < ciphertext.length; i++) { System.out.print(ciphertext[i] + " "); } cipher.init(Cipher.DECRYPT_MODE, key); byte[] decryptedText = cipher.doFinal(ciphertext); System.out.println(new String(decryptedText, "UTF8")); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String text = "java2s"; KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish"); keyGenerator.init(128);//from w w w .j a va 2 s .c o m Key key = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] ciphertext = cipher.doFinal(text.getBytes("UTF8")); for (int i = 0; i < ciphertext.length; i++) { System.out.print(ciphertext[i] + " "); } cipher.init(Cipher.DECRYPT_MODE, key); byte[] decryptedText = cipher.doFinal(ciphertext); System.out.println(new String(decryptedText, "UTF8")); }
From source file:de.tum.i13.ConvertCsvToProtobuf.java
public static void main(String args[]) { try {// w w w .j a v a2 s .com LineIterator it = FileUtils.lineIterator(new File("/Users/manit/Projects/sdcbenchmark/Dataset/debscsv"), "UTF-8"); FileOutputStream out = new FileOutputStream("/Users/manit/Projects/sdcbenchmark/Dataset/debsprotobuf", true); while (it.hasNext()) { String csvLine = (String) it.next(); byte[] csvLineBytes = csvLine.getBytes(); String line = new String(csvLineBytes, StandardCharsets.UTF_8); Debs2015Protos.Taxitrip.Builder builder = Debs2015Protos.Taxitrip.newBuilder(); String[] splitted = line.split(","); builder.setMedallion(splitted[0]); builder.setHackLicense(splitted[1]); builder.setPickupDatetime(splitted[2]); builder.setDropoffDatetime(splitted[3]); builder.setTripTimeInSecs(Integer.parseInt(splitted[4])); builder.setTripDistance(Float.parseFloat(splitted[5])); builder.setPickupLongitude(Float.parseFloat(splitted[6])); builder.setPickupLatitude(Float.parseFloat(splitted[7])); builder.setDropoffLongitude(Float.parseFloat(splitted[8])); builder.setDropoffLatitude(Float.parseFloat(splitted[9])); builder.setPaymentType(splitted[10]); builder.setFareAmount(Float.parseFloat(splitted[11])); builder.setSurcharge(Float.parseFloat(splitted[12])); builder.setMtaTax(Float.parseFloat(splitted[13])); builder.setTipAmount(Float.parseFloat(splitted[14])); builder.setTollsAmount(Float.parseFloat(splitted[15])); builder.setTotalAmount(Float.parseFloat(splitted[16])); builder.build().writeDelimitedTo(out); } out.close(); } catch (Exception e) { e.printStackTrace(); } }