Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 11 package org.eclipse.core.internal.utils; 12 13 import java.io.UnsupportedEncodingException ; 14 15 public class Convert { 16 17 20 public static String fromUTF8(byte[] b) { 21 String result; 22 try { 23 result = new String (b, "UTF8"); } catch (UnsupportedEncodingException e) { 25 result = new String (b); 26 } 27 return result; 28 } 29 30 33 public static byte[] toUTF8(String s) { 34 byte[] result; 35 try { 36 result = s.getBytes("UTF8"); } catch (UnsupportedEncodingException e) { 38 result = s.getBytes(); 39 } 40 return result; 41 } 42 43 48 public static byte[] longToBytes(long value) { 49 50 byte[] bytes = new byte[8]; 52 53 60 for (int i = 0; i < bytes.length; i++) { 61 bytes[(bytes.length - 1) - i] = (byte) value; 62 value >>>= 8; 63 } 64 65 return bytes; 66 } 67 68 73 public static long bytesToLong(byte[] value) { 74 75 long longValue = 0L; 76 77 for (int i = 0; i < value.length; i++) { 79 longValue <<= 8; 81 longValue ^= value[i] & 0xFF; 82 } 83 84 return longValue; 85 } 86 } 87
| Popular Tags
|