List of usage examples for java.lang String valueOf
public static String valueOf(double d)
From source file:Main.java
public static String bytesToIpPortString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 4; i++) { int Ip;// w w w . jav a2 s .c o m if (bytes[i] < 0) { Ip = bytes[i] + 256; } else { Ip = bytes[i]; } sb.append(String.valueOf(Ip)); if (i < 3) { sb.append("."); } else { sb.append(":"); } } int portHigh = (bytes[5] >= 0 ? bytes[5] : bytes[5] + 256); int portLow = (bytes[4] >= 0 ? bytes[4] : bytes[4] + 256); int port = portHigh * 256 + portLow; sb.append(String.valueOf(port)); return sb.toString(); }
From source file:Main.java
protected static String display(byte[] array) { char[] val = new char[2 * array.length]; String hex = "0123456789abcdef"; for (int i = 0; i < array.length; i++) { int b = array[i] & 0xff; val[2 * i] = hex.charAt(b >>> 4); val[2 * i + 1] = hex.charAt(b & 15); }/*from www . ja v a 2s.c om*/ return String.valueOf(val); }
From source file:Main.java
public static String dashToCamelCase(String name, boolean firstLetterUpper) { int currIndex = 0, dashIndex; StringBuilder camelName = new StringBuilder(name.length()); if (firstLetterUpper && !name.isEmpty()) { camelName.append(String.valueOf(name.charAt(0)).toUpperCase(Locale.ENGLISH)); currIndex = 1;//from w w w . ja v a 2 s . co m } while (currIndex < name.length() && (dashIndex = name.indexOf('-', currIndex)) >= 0) { camelName.append(name.substring(currIndex, dashIndex)); if (dashIndex + 1 < name.length()) { camelName.append(String.valueOf(name.charAt(dashIndex + 1)).toUpperCase(Locale.ENGLISH)); } currIndex = dashIndex + 2; } if (currIndex < name.length()) { camelName.append(name.substring(currIndex)); } return camelName.toString(); }
From source file:Main.java
public static String formatTime(long timestamp) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/*from w w w. ja va 2 s . c om*/ return sdf.format(new Timestamp(timestamp)); } catch (Exception e) { e.printStackTrace(); } return String.valueOf(timestamp); }
From source file:Main.java
private static void insertT9Key(@NonNull StringBuilder t9KeyBuilder, @NonNull String t9Str) { if (t9Str.length() == 0) return;/* w w w. java 2 s . c o m*/ int index = -1; while ((index = t9KeyBuilder.indexOf(String.valueOf(T9_KEYS_DIVIDER), index + 1)) >= 0) { t9KeyBuilder.insert(index, t9Str); index += t9Str.length(); } }
From source file:Main.java
public static void openContactInfo(final Context context, final long contactid) { final Intent intent = new Intent(Intent.ACTION_VIEW); final Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactid)); intent.setData(uri);/*ww w .j a va 2 s. com*/ context.startActivity(intent); }
From source file:Main.java
public static <T> void assertNotEquals(@NonNull T object, @NonNull T anotherObject, @NonNull String parameterName) throws AssertionError { check(object == anotherObject || object.equals(anotherObject), parameterName + " can't be equal to " + String.valueOf(anotherObject) + "."); }
From source file:Main.java
public static String createXML(SortedMap<String, Object> parameters) { StringBuilder buffer = new StringBuilder(); buffer.append("<xml>"); for (Entry<String, Object> entry : parameters.entrySet()) { String k = (String) entry.getKey(); String v = String.valueOf(entry.getValue()); if (!"null".equals(v) && !"".equals(v)) { buffer.append("<" + k + ">" + v + "</" + k + ">" + "\r\n"); }// w w w .j av a 2 s. c o m } buffer.append("</xml>"); return buffer.toString(); }
From source file:Main.java
public static String toUtf8String(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 0 && c <= 255) { sb.append(c);/*from ww w .j a v a 2s . c o m*/ } else { byte[] b; try { b = String.valueOf(c).getBytes("utf-8"); } catch (Exception ex) { System.out.println(ex); b = new byte[0]; } for (int j = 0; j < b.length; j++) { int k = b[j]; if (k < 0) k += 256; sb.append("%" + Integer.toHexString(k).toUpperCase()); } } } return sb.toString(); }
From source file:Main.java
public static void getTelephonyManagerMethods(Context context) { String out;//from ww w . j a v a 2 s.c om try { File dir = new File(String.valueOf(context.getFilesDir())); // create the file in which we will write the contents String fileName = "telephony.txt"; File file = new File(dir, fileName); FileOutputStream os = new FileOutputStream(file); Class<?> c = Class.forName(GENERIC); Method[] cm = c.getDeclaredMethods(); for (Method m : cm) { out = m.toString() + "\n"; os.write(out.getBytes()); } os.close(); } catch (Exception e) { e.printStackTrace(); } }