Class Utilities

java.lang.Object
com.itextpdf.text.Utilities

public class Utilities extends Object
A collection of convenience methods that were present in many different iText classes.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object[][]
    addToArray(Object[][] original, Object[] item)
    Utility method to extend an array.
    static boolean
    Checks for a true/false value of a key in a Properties object.
    static String
    convertFromUtf32(int codePoint)
    Converts a UTF32 code point value to a String with the corresponding character(s).
    static String
    convertToHex(byte[] bytes)
    Converts an array of bytes to a String of hexadecimal values
    static int
    convertToUtf32(char[] text, int idx)
    Converts a unicode character in a character array to a UTF 32 code point value.
    static int
    convertToUtf32(char highSurrogate, char lowSurrogate)
    Returns the code point of a UTF32 character corresponding with a high and a low surrogate value.
    static int
    convertToUtf32(String text, int idx)
    Converts a unicode character in a String to a UTF32 code point value
    static char[]
    copyOfRange(char[] original, int from, int to)
    Copies the specified range of the specified array into a new array.
    static <K, V> Set<K>
    getKeySet(Hashtable<K,V> table)
    Deprecated.
    static final float
    inchesToMillimeters(float value)
    Measurement conversion from inches to millimeters.
    static final float
    inchesToPoints(float value)
    Measurement conversion from inches to points.
    static boolean
    Check if the value of a character belongs to a certain interval that indicates it's the higher part of a surrogate pair.
    static boolean
    Check if the value of a character belongs to a certain interval that indicates it's the lower part of a surrogate pair.
    static boolean
    isSurrogatePair(char[] text, int idx)
    Checks if two subsequent characters in a character array are are the higher and the lower character in a surrogate pair (and therefore eligible for conversion to a UTF 32 character).
    static boolean
    isSurrogatePair(String text, int idx)
    Checks if two subsequent characters in a String are are the higher and the lower character in a surrogate pair (and therefore eligible for conversion to a UTF 32 character).
    static final float
    millimetersToInches(float value)
    Measurement conversion from millimeters to inches.
    static final float
    millimetersToPoints(float value)
    Measurement conversion from millimeters to points.
    static final float
    pointsToInches(float value)
    Measurement conversion from points to inches.
    static final float
    pointsToMillimeters(float value)
    Measurement conversion from points to millimeters.
    static String
    Reads the contents of a file to a String.
    static String
    Reads the contents of a file to a String.
    static void
    skip(InputStream is, int size)
    This method is an alternative for the InputStream.skip() -method that doesn't seem to work properly for big values of size .
    static URL
    toURL(String filename)
    This method makes a valid URL from a given filename.
    static String
    Unescapes an URL.

    Methods inherited from class java.lang.Object

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

    • Utilities

      public Utilities()
  • Method Details

    • getKeySet

      @Deprecated public static <K, V> Set<K> getKeySet(Hashtable<K,V> table)
      Deprecated.
      Gets the keys of a Hashtable. Marked as deprecated, not used anywhere anymore.
      Type Parameters:
      K - type for the key
      V - type for the value
      Parameters:
      table - a Hashtable
      Returns:
      the keyset of a Hashtable (or an empty set if table is null)
    • addToArray

      public static Object[][] addToArray(Object[][] original, Object[] item)
      Utility method to extend an array.
      Parameters:
      original - the original array or null
      item - the item to be added to the array
      Returns:
      a new array with the item appended
    • checkTrueOrFalse

      public static boolean checkTrueOrFalse(Properties attributes, String key)
      Checks for a true/false value of a key in a Properties object.
      Parameters:
      attributes -
      key -
      Returns:
      a true/false value of a key in a Properties object
    • unEscapeURL

      public static String unEscapeURL(String src)
      Unescapes an URL. All the "%xx" are replaced by the 'xx' hex char value.
      Parameters:
      src - the url to unescape
      Returns:
      the unescaped value
    • toURL

      public static URL toURL(String filename) throws MalformedURLException
      This method makes a valid URL from a given filename.

      This method makes the conversion of this library from the JAVA 2 platform to a JDK1.1.x-version easier.

      Parameters:
      filename - a given filename
      Returns:
      a valid URL
      Throws:
      MalformedURLException
    • skip

      public static void skip(InputStream is, int size) throws IOException
      This method is an alternative for the InputStream.skip() -method that doesn't seem to work properly for big values of size .
      Parameters:
      is - the InputStream
      size - the number of bytes to skip
      Throws:
      IOException
    • millimetersToPoints

      public static final float millimetersToPoints(float value)
      Measurement conversion from millimeters to points.
      Parameters:
      value - a value in millimeters
      Returns:
      a value in points
      Since:
      2.1.2
    • millimetersToInches

      public static final float millimetersToInches(float value)
      Measurement conversion from millimeters to inches.
      Parameters:
      value - a value in millimeters
      Returns:
      a value in inches
      Since:
      2.1.2
    • pointsToMillimeters

      public static final float pointsToMillimeters(float value)
      Measurement conversion from points to millimeters.
      Parameters:
      value - a value in points
      Returns:
      a value in millimeters
      Since:
      2.1.2
    • pointsToInches

      public static final float pointsToInches(float value)
      Measurement conversion from points to inches.
      Parameters:
      value - a value in points
      Returns:
      a value in inches
      Since:
      2.1.2
    • inchesToMillimeters

      public static final float inchesToMillimeters(float value)
      Measurement conversion from inches to millimeters.
      Parameters:
      value - a value in inches
      Returns:
      a value in millimeters
      Since:
      2.1.2
    • inchesToPoints

      public static final float inchesToPoints(float value)
      Measurement conversion from inches to points.
      Parameters:
      value - a value in inches
      Returns:
      a value in points
      Since:
      2.1.2
    • isSurrogateHigh

      public static boolean isSurrogateHigh(char c)
      Check if the value of a character belongs to a certain interval that indicates it's the higher part of a surrogate pair.
      Parameters:
      c - the character
      Returns:
      true if the character belongs to the interval
      Since:
      2.1.2
    • isSurrogateLow

      public static boolean isSurrogateLow(char c)
      Check if the value of a character belongs to a certain interval that indicates it's the lower part of a surrogate pair.
      Parameters:
      c - the character
      Returns:
      true if the character belongs to the interval
      Since:
      2.1.2
    • isSurrogatePair

      public static boolean isSurrogatePair(String text, int idx)
      Checks if two subsequent characters in a String are are the higher and the lower character in a surrogate pair (and therefore eligible for conversion to a UTF 32 character).
      Parameters:
      text - the String with the high and low surrogate characters
      idx - the index of the 'high' character in the pair
      Returns:
      true if the characters are surrogate pairs
      Since:
      2.1.2
    • isSurrogatePair

      public static boolean isSurrogatePair(char[] text, int idx)
      Checks if two subsequent characters in a character array are are the higher and the lower character in a surrogate pair (and therefore eligible for conversion to a UTF 32 character).
      Parameters:
      text - the character array with the high and low surrogate characters
      idx - the index of the 'high' character in the pair
      Returns:
      true if the characters are surrogate pairs
      Since:
      2.1.2
    • convertToUtf32

      public static int convertToUtf32(char highSurrogate, char lowSurrogate)
      Returns the code point of a UTF32 character corresponding with a high and a low surrogate value.
      Parameters:
      highSurrogate - the high surrogate value
      lowSurrogate - the low surrogate value
      Returns:
      a code point value
      Since:
      2.1.2
    • convertToUtf32

      public static int convertToUtf32(char[] text, int idx)
      Converts a unicode character in a character array to a UTF 32 code point value.
      Parameters:
      text - a character array that has the unicode character(s)
      idx - the index of the 'high' character
      Returns:
      the code point value
      Since:
      2.1.2
    • convertToUtf32

      public static int convertToUtf32(String text, int idx)
      Converts a unicode character in a String to a UTF32 code point value
      Parameters:
      text - a String that has the unicode character(s)
      idx - the index of the 'high' character
      Returns:
      the codepoint value
      Since:
      2.1.2
    • convertFromUtf32

      public static String convertFromUtf32(int codePoint)
      Converts a UTF32 code point value to a String with the corresponding character(s).
      Parameters:
      codePoint - a Unicode value
      Returns:
      the corresponding characters in a String
      Since:
      2.1.2
    • readFileToString

      public static String readFileToString(String path) throws IOException
      Reads the contents of a file to a String.
      Parameters:
      path - the path to the file
      Returns:
      a String with the contents of the file
      Throws:
      IOException
      Since:
      iText 5.0.0
    • readFileToString

      public static String readFileToString(File file) throws IOException
      Reads the contents of a file to a String.
      Parameters:
      file - a file
      Returns:
      a String with the contents of the file
      Throws:
      IOException - if file was not found or could not be read.
      Since:
      iText 5.0.0
    • convertToHex

      public static String convertToHex(byte[] bytes)
      Converts an array of bytes to a String of hexadecimal values
      Parameters:
      bytes - a byte array
      Returns:
      the same bytes expressed as hexadecimal values
    • copyOfRange

      public static char[] copyOfRange(char[] original, int from, int to)
      Copies the specified range of the specified array into a new array. The initial index of the range (from) must lie between zero and original.length, inclusive. The value at original[from] is placed into the initial element of the copy (unless from == original.length or from == to). Values from subsequent elements in the original array are placed into subsequent elements in the copy. The final index of the range (to), which must be greater than or equal to from, may be greater than original.length, in which case '\\u000' is placed in all elements of the copy whose index is greater than or equal to original.length - from. The length of the returned array will be to - from.
      Parameters:
      original - the array from which a range is to be copied
      from - the initial index of the range to be copied, inclusive
      to - the final index of the range to be copied, exclusive. (This index may lie outside the array.)
      Returns:
      a new array containing the specified range from the original array, truncated or padded with null characters to obtain the required length
      Throws:
      ArrayIndexOutOfBoundsException - if from < 0 or from > original.length
      IllegalArgumentException - if from > to
      NullPointerException - if original is null
      Since:
      1.6