Example usage for java.lang Character SIZE

List of usage examples for java.lang Character SIZE

Introduction

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

Prototype

int SIZE

To view the source code for java.lang Character SIZE.

Click Source Link

Document

The number of bits used to represent a char value in unsigned binary form, constant 16 .

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Character.SIZE:" + Character.SIZE);
}

From source file:Main.java

public static byte[] convertStringToBytes(String str) {
    byte[] bytes = new byte[str.length() * Character.SIZE];
    System.arraycopy(str.toCharArray(), 0, bytes, 0, bytes.length);
    return bytes;
}

From source file:Main.java

public static String convertByteToString(byte[] bytes) {
    char[] chars = new char[bytes.length / Character.SIZE];
    System.arraycopy(bytes, 0, chars, 0, bytes.length);
    return new String(chars);
}

From source file:com.bah.culvert.util.Bytes.java

/**
 * Convert a character to a byte[]/*  w ww. j a  v a 2s  .c  o  m*/
 * @param c
 * @return
 */
public static byte[] toBytes(char c) {
    int bytes = Character.SIZE / 8;
    return ByteBuffer.allocate(bytes).putChar(c).array();
}

From source file:org.apache.pig.impl.util.avro.AvroTupleWrapper.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private long getMemorySize(final IndexedRecord r) {
    int total = 0;
    final int bitsPerByte = 8;
    for (Field f : r.getSchema().getFields()) {
        switch (f.schema().getType()) {
        case BOOLEAN:
        case ENUM:
        case INT:
            total += Integer.SIZE << bitsPerByte;
            break;
        case DOUBLE:
            total += Double.SIZE << bitsPerByte;
            break;
        case FLOAT:
            total += Float.SIZE << bitsPerByte;
            break;
        case NULL:
            break;
        case STRING:
            total += ((String) r.get(f.pos())).length() * (Character.SIZE << bitsPerByte);
            break;
        case BYTES:
            total += ((Byte[]) r.get(f.pos())).length;
            break;
        case RECORD:
            total += new AvroTupleWrapper((IndexedRecord) r.get(f.pos())).getMemorySize();
            break;
        case ARRAY:
            total += new AvroBagWrapper((GenericArray) r.get(f.pos())).getMemorySize();
            break;
        }/*from ww w .ja  va  2  s.  c o  m*/
    }
    return total;
}