Class NumberUtil

java.lang.Object
org.codehaus.stax2.ri.typed.NumberUtil

public final class NumberUtil extends Object
Helper class that contains method for converting numeric values to and from String representations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Maximum number of characters in a serialized double is 26 (at least for Sun JDK; 19 digits for mantissa, 3 for exponent, signs for mantissa and exponent, decimal point, 'E'): but let's pad it up a little bit just to play it safe.
    static final int
    JDK serializes floats same way as doubles, so let's reserve as much space
    static final int
    Maximum number of characters in a serialized integer is 11; one for (minus) sign, and then up to 10 digits
    static final int
    Maximum number of characters in a serialized long is 21; one for (minus) sign, and then up to 20 digits
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    writeDouble(double value, byte[] buffer, int offset)
     
    static int
    writeDouble(double value, char[] buffer, int offset)
     
    static int
    writeFloat(float value, byte[] buffer, int offset)
     
    static int
    writeFloat(float value, char[] buffer, int offset)
     
    static int
    writeInt(int value, byte[] buffer, int offset)
     
    static int
    writeInt(int value, char[] buffer, int offset)
    Note: caller must ensure that there is room for least 11 characters (leading sign, and up to 10 digits) in buffer passed.
    static int
    writeLong(long value, byte[] buffer, int offset)
     
    static int
    writeLong(long value, char[] buffer, int offset)
    Note: caller must ensure that there is room for least 21 characters (leading sign, and up to 20 digits ) in buffer passed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_INT_CLEN

      public static final int MAX_INT_CLEN
      Maximum number of characters in a serialized integer is 11; one for (minus) sign, and then up to 10 digits
      See Also:
    • MAX_LONG_CLEN

      public static final int MAX_LONG_CLEN
      Maximum number of characters in a serialized long is 21; one for (minus) sign, and then up to 20 digits
      See Also:
    • MAX_DOUBLE_CLEN

      public static final int MAX_DOUBLE_CLEN
      Maximum number of characters in a serialized double is 26 (at least for Sun JDK; 19 digits for mantissa, 3 for exponent, signs for mantissa and exponent, decimal point, 'E'): but let's pad it up a little bit just to play it safe.
      See Also:
    • MAX_FLOAT_CLEN

      public static final int MAX_FLOAT_CLEN
      JDK serializes floats same way as doubles, so let's reserve as much space
      See Also:
  • Constructor Details

    • NumberUtil

      public NumberUtil()
  • Method Details

    • writeInt

      public static int writeInt(int value, char[] buffer, int offset)

      Note: caller must ensure that there is room for least 11 characters (leading sign, and up to 10 digits) in buffer passed.

      Returns:
      Offset within buffer after outputting int
    • writeInt

      public static int writeInt(int value, byte[] buffer, int offset)
    • writeLong

      public static int writeLong(long value, char[] buffer, int offset)

      Note: caller must ensure that there is room for least 21 characters (leading sign, and up to 20 digits ) in buffer passed.

      Returns:
      Offset within buffer after outputting int
    • writeLong

      public static int writeLong(long value, byte[] buffer, int offset)
    • writeFloat

      public static int writeFloat(float value, char[] buffer, int offset)
    • writeFloat

      public static int writeFloat(float value, byte[] buffer, int offset)
    • writeDouble

      public static int writeDouble(double value, char[] buffer, int offset)
    • writeDouble

      public static int writeDouble(double value, byte[] buffer, int offset)