Example usage for java.lang String getBytes

List of usage examples for java.lang String getBytes

Introduction

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

Prototype

public byte[] getBytes() 

Source Link

Document

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

Usage

From source file:Main.java

public static byte[] stringToBytes(String s) {
    return s == null ? new byte[] {} : s.getBytes();
}

From source file:Main.java

public static int encodeBodyDataLength(String[] values) {
    int length = 0;
    for (String value : values) {
        length += value.getBytes().length;
    }/*  w w  w  .ja  va  2s.  com*/
    return length;
}

From source file:Main.java

public static InputStream String2Inputstream(String str) {
    return new ByteArrayInputStream(str.getBytes());
}

From source file:Main.java

public static byte[] base64EncodeByte(final String data) {
    return Base64.encode(data.getBytes(), Base64.DEFAULT);
}

From source file:Main.java

public static String encrypt(String str) {
    return new String(Base64.encode(str.getBytes(), Base64.DEFAULT));
}

From source file:Main.java

public static InputStream string2Inputstream(String str) {
    return new ByteArrayInputStream(str.getBytes());
}

From source file:Main.java

public static String encode(String content) {
    return Base64.encodeToString(content.getBytes(), Base64.DEFAULT);
}

From source file:Main.java

public static void writeLine(OutputStream os, PrintWriter logWriter, String value) throws IOException {
    String line = value + "\n";
    os.write(line.getBytes());
    if (logWriter != null) {
        logWriter.println(value);//from  ww  w.j a v a  2s.  com
    }
}

From source file:Main.java

public static String getBASE64(String s) {
    return new String(Base64.encode(s.getBytes(), Base64.DEFAULT));
}

From source file:Main.java

public static String stringToHex(String string) {
    return bytesToHex(string.getBytes());
}