Class Misc

java.lang.Object
org.frankframework.util.Misc

public class Misc extends Object
Miscellaneous conversion functions.
  • Field Details

    • MESSAGE_SIZE_WARN_BY_DEFAULT_KEY

      public static final String MESSAGE_SIZE_WARN_BY_DEFAULT_KEY
      See Also:
    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
  • Constructor Details

    • Misc

      public Misc()
  • Method Details

    • insertAuthorityInUrlString

      public static String insertAuthorityInUrlString(String url, String authAlias, String username, String password)
    • byteArrayToString

      public static String byteArrayToString(byte[] input, String endOfLineString, boolean xmlEncode) throws IOException
      Converts a byte array into a string, and adds a specified string to the end of the converted string.
      Throws:
      IOException
      See Also:
    • getHostname

      public static String getHostname()
    • toFileSize

      public static long toFileSize(String value, long defaultValue)
      Converts the file size to bytes.
      Misc.toFileSize("14GB", 20); // gives out 15032385536
    • toFileSize

      public static String toFileSize(long bytes)
      See Also:
    • toFileSize

      public static String toFileSize(long bytes, boolean format)
      See Also:
    • toFileSize

      public static String toFileSize(long bytes, boolean format, boolean useSiUnits)
      Format bytes as human-readable text.
           String kbIecUnits = Misc.toFileSize(150000, false, false);                         // gives out "146KiB"
                 String mbIecUnits = Misc.toFileSize(15000000, true);                                 // gives out "14 MiB"
           String gbIecUnits = Misc.toFileSize(Long.parseLong("3221225472")); // gives out "3GiB"
      
                 String kbSiUnits = Misc.toFileSize(150000, true, false);                                             // gives out "150kB"
                 String mbSiUnits = Misc.toFileSize(15000000, true, true);                                            // gives out "15 MB"
                 String gbSiUnits = Misc.toFileSize(Long.parseLong("3221225472"), true, false);       // gives out "3GB"
       
      Parameters:
      bytes - Number of bytes. Should be positive, value is returned as string if negative.
      format - True to insert space between value and unit.
      useSiUnits - True to use metric (SI) units, aka powers of 1000. False to use binary (IEC), aka powers of 1024.
      Returns:
      Formatted string.
    • getMessageSizeWarnByDefault

      public static long getMessageSizeWarnByDefault()
    • listToString

      public static String listToString(List<String> list)
      Converts the list to a string. <pre> List<String> list = new ArrayList<>(); list.add("We Are"); list.add(" Frank"); String res = Misc.listToString(list); // res = "We Are Frank" </pre>
    • addItemsToList

      public static void addItemsToList(Collection<String> collection, String list, String collectionDescription, boolean lowercase)
      Adds items on a string, added by comma separator (ex: "1,2,3"), into a list.
      Parameters:
      collectionDescription - description of the list
    • getAge

      public static String getAge(long value)
    • getDurationInMs

      public static String getDurationInMs(long value)
    • parseAge

      public static long parseAge(String value, long defaultValue)
      Returns:
      'age' in milliseconds.
    • cleanseMessage

      public static String cleanseMessage(String inputString, String regexForHiding, IMessageBrowser.HideMethod hideMethod)
      Edits the input string according to the regex and the hide method specified.
      See Also:
    • getBuildOutputDirectory

      public static String getBuildOutputDirectory()
    • addToSortedListUnique

      public static <T> void addToSortedListUnique(List<T> list, T item)
    • addToSortedListNonUnique

      public static <T> void addToSortedListNonUnique(List<T> list, T item)
    • jsonPretty

      public static String jsonPretty(String json)
    • asInputSource

      public static InputSource asInputSource(URL url) throws IOException
      Throws:
      IOException