Package psiprobe

Class Utils


  • public final class Utils
    extends Object
    Misc. static helper methods.
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
        The Constant logger.
    • Constructor Detail

      • Utils

        private Utils()
        Prevent Instantiation.
    • Method Detail

      • readFile

        public static String readFile​(File file,
                                      String charsetName)
                               throws IOException
        Reads a file on disk. The method uses default file encoding (see: file.encoding system property)
        Parameters:
        file - to be read
        charsetName - the charset name
        Returns:
        String representation of the file contents
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • readStream

        public static String readStream​(InputStream is,
                                        String charsetName)
                                 throws IOException
        Reads strings from the intput stream using the given charset. This method closes the input stream after it has been consumed.

        This method uses the system's default charset if the given one is unsupported.

        Parameters:
        is - the stream from which to read
        charsetName - the charset to use when reading the stream
        Returns:
        the contents of the given input stream
        Throws:
        IOException - if reading from the stream fails spectacularly
      • delete

        public static void delete​(File file)
        Delete.
        Parameters:
        file - the file
      • toInt

        public static int toInt​(String num,
                                int defaultValue)
        To int.
        Parameters:
        num - the num
        defaultValue - the default value
        Returns:
        the int
      • toIntHex

        public static int toIntHex​(String num,
                                   int defaultValue)
        To int hex.
        Parameters:
        num - the num
        defaultValue - the default value
        Returns:
        the int
      • toLong

        public static long toLong​(String num,
                                  long defaultValue)
        To long.
        Parameters:
        num - the num
        defaultValue - the default value
        Returns:
        the long
      • toLong

        public static long toLong​(Long num,
                                  long defaultValue)
        To long.
        Parameters:
        num - the num
        defaultValue - the default value
        Returns:
        the long
      • toFloat

        public static float toFloat​(String num,
                                    float defaultValue)
        To float.
        Parameters:
        num - the num
        defaultValue - the default value
        Returns:
        the float
      • getJspEncoding

        public static String getJspEncoding​(InputStream is)
                                     throws IOException
        Gets the jsp encoding.
        Parameters:
        is - the is
        Returns:
        the jsp encoding
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • sendFile

        public static void sendFile​(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    File file)
                             throws IOException
        Send file.
        Parameters:
        request - the request
        response - the response
        file - the file
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • getThreadByName

        public static Thread getThreadByName​(String name)
        Gets the thread by name.
        Parameters:
        name - the name
        Returns:
        the thread by name
      • highlightStream

        public static String highlightStream​(String name,
                                             InputStream input,
                                             String rendererName,
                                             String encoding)
                                      throws IOException
        Highlight stream.
        Parameters:
        name - the name
        input - the input
        rendererName - the renderer name
        encoding - the encoding
        Returns:
        the string
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • sendCompressedFile

        public static void sendCompressedFile​(javax.servlet.http.HttpServletResponse response,
                                              File file)
                                       throws IOException
        Send compressed file.
        Parameters:
        response - the response
        file - the file
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • leftPad

        protected static String leftPad​(String str,
                                        int len,
                                        String fill)
        Left pad.
        Parameters:
        str - the str
        len - the len
        fill - the fill
        Returns:
        the string
      • getNamesForLocale

        public static List<String> getNamesForLocale​(String baseName,
                                                     Locale locale)
        Gets the names for locale.
        Parameters:
        baseName - the base name
        locale - the locale
        Returns:
        the names for locale
      • isThreadingEnabled

        public static boolean isThreadingEnabled()
        Checks if is threading enabled.
        Returns:
        true, if is threading enabled