Class Size


  • public class Size
    extends Object
    This class has static methods to compute the size in bytes of java primitive types, primitive arrays, NIO buffers and more...
    Author:
    royer
    • Constructor Summary

      Constructors 
      Constructor Description
      Size()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Class<?> floatTypeFromSize​(int pNumberOfBytes)
      Returns a primitive float type given a number of bytes.
      static int fromString​(String pTypeName)
      Returns the size in bytes corresponding to a type described by a string (type name as string).
      static Class<?> integralTypeFromSize​(int pNumberOfBytes, boolean pSigned)
      Returns the class of an integral primitive type given a number of bytes
      static int of​(byte pPrimitive)
      Size in bytes for this primitive.
      static int of​(char pPrimitive)
      Size in bytes for this primitive.
      static int of​(double pPrimitive)
      Size in bytes for this primitive.
      static int of​(float pPrimitive)
      Size in bytes for this primitive.
      static int of​(int pPrimitive)
      Size in bytes for this primitive.
      static int of​(long pPrimitive)
      Size in bytes for this primitive.
      static int of​(short pPrimitive)
      Size in bytes for this primitive.
      static long of​(Object pObject)
      returns the size in bytes of the object (or class of an object).
      static long ofBridJPointer​(org.bridj.Pointer<?> pPointer)
      Returns the size in bytes of this BridJ pointer
      static long ofBuffer​(Buffer pBuffer)
      Returns the size in bytes of a NIO Buffer
      static int ofNativeTypeEnum​(NativeTypeEnum pNativeType)
      Return the size in bytes for a given native type
      static int ofPrimitive1DArray​(Object pArray)
      Returns the size in bytes of a 1D primitive array
      static int ofPrimitiveClass​(Class<?> pClass)
      Returns the size in bytes of this primitive type class
      static long ofSizedInBytes​(SizedInBytes pSizedInBytes)
      Returns the size in bytes of an object implementing SizedInBytes.
      static long ofString​(String pString)
      Returns the size in bytes of a Java String
    • Field Detail

      • DOUBLE

        public static int DOUBLE
      • FLOAT

        public static int FLOAT
      • HALFFLOAT

        public static int HALFFLOAT
      • LONG

        public static int LONG
      • INT

        public static int INT
      • SHORT

        public static int SHORT
      • CHAR

        public static int CHAR
      • BYTE

        public static int BYTE
      • DOUBLESHIFT

        public static int DOUBLESHIFT
      • FLOATSHIFT

        public static int FLOATSHIFT
      • LONGSHIFT

        public static int LONGSHIFT
      • INTSHIFT

        public static int INTSHIFT
      • SHORTSHIFT

        public static int SHORTSHIFT
      • CHARSHIFT

        public static int CHARSHIFT
      • BYTESHIFT

        public static int BYTESHIFT
    • Constructor Detail

      • Size

        public Size()
    • Method Detail

      • of

        public static long of​(Object pObject)
        returns the size in bytes of the object (or class of an object). This works for objects such as: byte.class, float[]{1,2,3},...
        Parameters:
        pObject - object, can be byte, byte.class, or byte[], NIO buffer object...
        Returns:
        size in bytes
      • of

        public static int of​(byte pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • of

        public static int of​(short pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • of

        public static int of​(char pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • of

        public static int of​(int pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • of

        public static int of​(long pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • of

        public static int of​(float pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • of

        public static int of​(double pPrimitive)
        Size in bytes for this primitive.
        Parameters:
        pPrimitive - primitive
        Returns:
        size in bytes
      • ofPrimitiveClass

        public static int ofPrimitiveClass​(Class<?> pClass)
        Returns the size in bytes of this primitive type class
        Parameters:
        pClass - primitive type class
        Returns:
        size in bytes
      • ofPrimitive1DArray

        public static int ofPrimitive1DArray​(Object pArray)
        Returns the size in bytes of a 1D primitive array
        Parameters:
        pArray - 1D primitive array
        Returns:
        array size in bytes
      • ofBuffer

        public static long ofBuffer​(Buffer pBuffer)
        Returns the size in bytes of a NIO Buffer
        Parameters:
        pBuffer - NIO buffer
        Returns:
        size in bytes
      • ofBridJPointer

        public static long ofBridJPointer​(org.bridj.Pointer<?> pPointer)
        Returns the size in bytes of this BridJ pointer
        Parameters:
        pPointer - BridJ pointer
        Returns:
        size in bytes
      • ofSizedInBytes

        public static long ofSizedInBytes​(SizedInBytes pSizedInBytes)
        Returns the size in bytes of an object implementing SizedInBytes.
        Parameters:
        pSizedInBytes - object
        Returns:
        size in bytes
      • ofNativeTypeEnum

        public static int ofNativeTypeEnum​(NativeTypeEnum pNativeType)
        Return the size in bytes for a given native type
        Parameters:
        pNativeType - native type
        Returns:
        size in bytes
      • ofString

        public static long ofString​(String pString)
        Returns the size in bytes of a Java String
        Parameters:
        pString - string
        Returns:
        size in bytes
      • fromString

        public static int fromString​(String pTypeName)
        Returns the size in bytes corresponding to a type described by a string (type name as string).
        Parameters:
        pTypeName - type name
        Returns:
        size in bytes
      • integralTypeFromSize

        public static Class<?> integralTypeFromSize​(int pNumberOfBytes,
                                                    boolean pSigned)
        Returns the class of an integral primitive type given a number of bytes
        Parameters:
        pNumberOfBytes - number of bytes in type
        pSigned - is signed?
        Returns:
        integral primitive type class
      • floatTypeFromSize

        public static Class<?> floatTypeFromSize​(int pNumberOfBytes)
        Returns a primitive float type given a number of bytes.
        Parameters:
        pNumberOfBytes - number of bytes in type
        Returns:
        float primitive type class