Example usage for java.lang String String

List of usage examples for java.lang String String

Introduction

In this page you can find the example usage for java.lang String String.

Prototype

public String(StringBuilder builder) 

Source Link

Document

Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

Usage

From source file:Main.java

public static String encode(String str, int time) {
    String result = new String(str);
    for (int i = 0; i < time; i++) {
        result = new String(Base64.encode(result.getBytes(), Base64.NO_WRAP));
    }//from   w  w w. j  a v a2  s. co m
    return result;
}

From source file:Main.java

public static byte[] convertIntToBCDBytes(int value) {
    int length = new String(value + "").length();
    if (length <= 2) {
        int first = value / 10;
        int second = value % 10;
        byte[] b = new byte[] { (byte) (first << 4 | second) };
        return b;
    } else if (length <= 4) {
        int first = (value / 1000) % 10;
        int second = (value / 100) % 10;
        int third = (value / 10) % 10;
        int fourth = value % 10;
        byte[] b = new byte[] { (byte) (first << 4 | second), (byte) (third << 4 | fourth) };
        return b;
    } else {/*ww  w. jav  a2s. com*/
        int prefirst = value / 10000;
        int first = (value / 1000) % 10;
        int second = (value / 100) % 10;
        int third = (value / 10) % 10;
        int fourth = value % 10;
        byte[] b = new byte[] { (byte) prefirst, (byte) (first << 4 | second), (byte) (third << 4 | fourth) };
        return b;
    }
}

From source file:Main.java

public static String bytesToString(byte[] bytes) {
    return bytes != null ? new String(bytes) : null;
}

From source file:Main.java

private static String repeat(final int i, final CharSequence text) {
    return new String(new char[i]).replace("\0", text);
}

From source file:Main.java

public static String toString(byte[] b) {
    if (b == null) {
        return null;
    }/*w w w . j ava 2 s . co  m*/

    return new String(b);
}

From source file:Main.java

public static String decodeBase64String(String str) {
    try {//from  w  w  w. j av a 2  s.  c o  m
        return new String(Base64.decode(str, Base64.DEFAULT));
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static boolean isMacAddressAllZore(String addr) {
    String source = new String(addr);
    String str = source.replaceAll(":", "0");
    String[] splits = str.split("0");

    return splits.length == 0;
}

From source file:Main.java

public static String encodeBase64String(String str) {
    try {// ww  w  .  jav a 2  s  . c o m

        return new String(Base64.encode(str.getBytes(), Base64.DEFAULT));
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String convertByteToString(byte[] bt) {
    if (bt == null) {
        return null;
    }/*from w ww .  jav  a 2s.co m*/
    return new String(bt);
}

From source file:Main.java

public static int hexTo10(String hex) {
    if (hex == null) {
        hex = new String("FFFFFF");
    }/*  w ww . j  a  v a2 s.co m*/
    int h = 0xff000000;
    int b = Integer.parseInt(hex, 16);
    return h + b;
}