Package psiprobe
Class Utils
- java.lang.Object
-
- psiprobe.Utils
-
public final class Utils extends Object
Misc. static helper methods.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
logger
The Constant logger.
-
Constructor Summary
Constructors Modifier Constructor Description private
Utils()
Prevent Instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
delete(File file)
Delete.static String
getJspEncoding(InputStream is)
Gets the jsp encoding.static List<String>
getNamesForLocale(String baseName, Locale locale)
Gets the names for locale.static Thread
getThreadByName(String name)
Gets the thread by name.static String
highlightStream(String name, InputStream input, String rendererName, String encoding)
Highlight stream.static boolean
isThreadingEnabled()
Checks if is threading enabled.protected static String
leftPad(String str, int len, String fill)
Left pad.static String
readFile(File file, String charsetName)
Reads a file on disk.static String
readStream(InputStream is, String charsetName)
Reads strings from the intput stream using the given charset.static void
sendCompressedFile(javax.servlet.http.HttpServletResponse response, File file)
Send compressed file.static void
sendFile(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, File file)
Send file.static float
toFloat(String num, float defaultValue)
To float.static int
toInt(String num, int defaultValue)
To int.static int
toIntHex(String num, int defaultValue)
To int hex.static long
toLong(Long num, long defaultValue)
To long.static long
toLong(String num, long defaultValue)
To long.
-
-
-
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 readcharsetName
- 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 readcharsetName
- 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 numdefaultValue
- the default value- Returns:
- the int
-
toIntHex
public static int toIntHex(String num, int defaultValue)
To int hex.- Parameters:
num
- the numdefaultValue
- the default value- Returns:
- the int
-
toLong
public static long toLong(String num, long defaultValue)
To long.- Parameters:
num
- the numdefaultValue
- the default value- Returns:
- the long
-
toLong
public static long toLong(Long num, long defaultValue)
To long.- Parameters:
num
- the numdefaultValue
- the default value- Returns:
- the long
-
toFloat
public static float toFloat(String num, float defaultValue)
To float.- Parameters:
num
- the numdefaultValue
- 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 requestresponse
- the responsefile
- 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 nameinput
- the inputrendererName
- the renderer nameencoding
- 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 responsefile
- 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 strlen
- the lenfill
- the fill- Returns:
- the string
-
getNamesForLocale
public static List<String> getNamesForLocale(String baseName, Locale locale)
Gets the names for locale.- Parameters:
baseName
- the base namelocale
- the locale- Returns:
- the names for locale
-
isThreadingEnabled
public static boolean isThreadingEnabled()
Checks if is threading enabled.- Returns:
- true, if is threading enabled
-
-