Java Utililty Methods Type Size

List of utility methods to do Type Size

Description

The list of methods to do Type Size are organized into topic(s).

Method

intsizeOf(Class cls)
size Of
if (cls == boolean.class)
    return 1;
if (cls == byte.class)
    return 1;
if (cls == char.class)
    return 2;
if (cls == short.class)
    return 2;
...
intsizeOf(Class clz)
Get the size of a primitive type.
switch (clz.getName()) {
case "int":
    return Integer.BYTES;
case "short":
    return Short.BYTES;
case "long":
    return Long.BYTES;
case "double":
...
intsizeOf(double v)
size Of
return 8;
intsizeOf(int fieldNumber)
size Of
return fieldNumber > 15 ? 2 : 1;
intsizeOf(int tagNumber, int contentLength)
Computes the DER-encoded size of content with a specified tag number.
if (tagNumber < 0 || contentLength < 0) {
    throw new IllegalArgumentException(
            "Invalid tagNumber/contentLength: " + tagNumber + ", " + contentLength);
int len = 0;
if (tagNumber <= 30) {
    len++; 
} else {
...
intsizeOf(int value)
size Of
if (value < 0)
    value = ~value;
value >>= BYTE_OFFSET - 1;
for (int i = 1; i < 4; i++) {
    if (value == 0)
        return i;
    value >>= BYTE_OFFSET;
return 4;
intsizeOf(int[] arr)
size Of
return arr == null ? 0 : arr.length;
intsizeOf(String str)
Returns the number of bytes required to be written out for the given object.
if (str == null) {
    return 1;
} else {
    return 5 + (2 * str.length());
intsizeOf(String type)
size Of
if ("byte".equals(type)) {
    return 1;
} else if ("char".equals(type)) {
    return 1;
} else if ("double".equals(type)) {
    return 2;
} else if ("float".equals(type)) {
    return 1;
...
intsizeOf(String typeDescriptor)
Return the size of a type.
if (typeDescriptor.length() != 1) {
    return 1;
char ch = typeDescriptor.charAt(0);
if (ch == 'J' || ch == 'D') {
    return 2;
} else {
    return 1;
...