Class Format
java.lang.Object
ecmwf.common.text.Format
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
The Class DuplicatedChooseScore. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Find the best score to select the line.static String
The options are in the following format: (.= /readme.txt) standby=yes (== {avhrr_n.*}) standby=never;delay=2h And this method looks for the first line which apply to the selected key.static String
cleanTextContent
(String text) Clean text content.static String
Compress.static String
Decode.static String
escapeHTML
(String s) Escape html.extractSearchParameters
(String defaultOptionName, String input) Extract search parameters.static String
formatBoolean
(boolean bool) Format boolean.static String
Format current time.static String
formatDuration
(long duration) Format duration.static String
formatDuration
(long start, long stop) Format duration.static String
formatLong
(long n, int width) Format long.static String
formatLong
(long n, int width, boolean zero) Format long.static String
formatPercentage
(long size, long sent) Format percentage.static String
formatPercentageOf
(long size, long sent) Format percentage with the of, over and left to comment.static String
formatRate
(long size, long duration) Format the transfer rate in GBytes/s or MBytes/s or KBytes/s or Bytes/s depending of the size.static String
formatSize
(long bytes) Format size.static String
formatString
(Object text, int width) Format string.static String
formatString
(Object text, int width, boolean onRight) Format string.static String
formatString
(String text, int width) Format string.static String
formatString
(String text, int width, char empty) Format string.static String
formatString
(String text, int width, char empty, boolean onRight) Format string.static String
formatTime
(long date) Format time.static String
formatTime
(String format, long date) Format time.static String
formatTime
(Timestamp date) Format time.static String
formatUntil
(long lastDate) Format until.static String
formatValue
(long value, int width) Format value.static String
fromXMLValue
(String target) From xml value.static String
getClassName
(Object object) Gets the class name.static String
getCleanPath
(String path) Clean the path by removing all occurrences of "///" by "/", all "\" by "/" and all trailing "/".static long
getDuration
(String duration) Gets the duration with default value in hours.static String
Gets the ftp list.static String
getHash
(byte[] bytes) Return a hash of the string.static String
getHostAddress
(String host) Gets the host address.static String
getHostName
(String host) Gets the host name.static String
getLastMessage
(Throwable t, String defaultMessage) Gets the message.static double
getMBitsPerSeconds
(long size, long duration) Get the transfer rate in Mbits/s.static String
Gets the message.static String
getMessage
(Throwable t, String defaultMessage, int limit) Gets the message.static String[]
getParameters
(String message, String token) Gets the parameters.static String
Hide.static boolean
isValidEmail
(String email) Check if this is a valid email.static boolean
Check if this is a valid identifier (with letters, digits and allowed characters).static boolean
_matches.static boolean
matchesGlobPattern
(String pattern, String input) Matches glob pattern.static String
normalizePath
(String path) Normalize path.static String
objectToString
(Object object) Object to string.static long
parseDurationWithDefaultInMillis
(String duration) Parse the duration with default value in milliseconds.static void
replaceAll
(StringBuilder target, String name, Object value) Replace all.static String
replaceAll
(String target, String name, Object value) Replace all.static void
replaceAllExt
(StringBuilder target, String name, String value) Replace all.static String
replaceAllExt
(String target, String name, String value) Replace all.static byte[]
Converts into bytes.static byte[]
Converts into bytes.static String
toHexa
(byte[] bytes) Converts into hexa.static <E> String
Converts into list.static <E> String
Converts into list.static double
toMBits
(long bytes) Convert Bytes in Mbits.static Object
toObject
(byte[] bytes) Converts into object.static long
Converts into time.static long
Converts into long.static String
toWMOFormat
(String name) Converts into wmo format.static String
toXMLValue
(String target) Converts into xml value.static String
trimString
(String text, int maxSize) Trim string.static String
trimString
(String message, String empty) Trim string.static String
uncompress
(byte[] bytes) Uncompress.static String
uncompress
(String str) Uncompress.static String
unix2sqlWildcards
(String unix) Convert unix 2 sql wildcards and also escape the special sql characters '%' and '_'.static String
unixToWindows
(String text) Unix to windows.static byte[]
windowsToUnix
(byte[] data, int offset, int len) Windows to unix.static String
windowsToUnix
(String text) Windows to unix.
-
Method Details
-
unix2sqlWildcards
-
isValidEmail
Check if this is a valid email.- Parameters:
email
- the email- Returns:
- valid
-
isValidId
-
escapeHTML
-
formatSize
Format size.- Parameters:
bytes
- the bytes- Returns:
- the string
-
toMBits
public static double toMBits(long bytes) Convert Bytes in Mbits.- Parameters:
bytes
- the bytes- Returns:
- the string
-
formatTime
-
formatTime
Format time.- Parameters:
date
- the date- Returns:
- the string
-
formatCurrentTime
-
formatTime
-
formatDuration
Format duration.- Parameters:
start
- the startstop
- the stop- Returns:
- the string
-
toList
-
toList
-
formatDuration
Format duration.- Parameters:
duration
- the duration- Returns:
- the string
-
formatBoolean
Format boolean.- Parameters:
bool
- the bool- Returns:
- the string
-
formatLong
Format long.- Parameters:
n
- the nwidth
- the width- Returns:
- the string
-
formatLong
Format long.- Parameters:
n
- the nwidth
- the widthzero
- the zero- Returns:
- the string
-
formatRate
Format the transfer rate in GBytes/s or MBytes/s or KBytes/s or Bytes/s depending of the size.- Parameters:
size
- the sizeduration
- the duration- Returns:
- the string
-
getMBitsPerSeconds
public static double getMBitsPerSeconds(long size, long duration) Get the transfer rate in Mbits/s.- Parameters:
size
- the sizeduration
- the duration- Returns:
- the string
-
formatPercentage
Format percentage.- Parameters:
size
- the sizesent
- the sent- Returns:
- the string
-
formatPercentageOf
Format percentage with the of, over and left to comment.- Parameters:
size
- the sizesent
- the sent- Returns:
- the string
-
formatString
-
formatString
-
formatString
-
formatString
-
formatString
-
parseDurationWithDefaultInMillis
Parse the duration with default value in milliseconds.- Parameters:
duration
- the duration string- Returns:
- the duration
- Throws:
NumberFormatException
- the number format exception
-
getDuration
Gets the duration with default value in hours.- Parameters:
duration
- the duration- Returns:
- the duration
- Throws:
NumberFormatException
- the number format exception
-
formatValue
Format value.- Parameters:
value
- the valuewidth
- the width- Returns:
- the string
-
trimString
-
formatUntil
Format until.- Parameters:
lastDate
- the last date- Returns:
- the string
-
fromXMLValue
-
hide
-
windowsToUnix
-
windowsToUnix
public static byte[] windowsToUnix(byte[] data, int offset, int len) Windows to unix.- Parameters:
data
- the dataoffset
- the offsetlen
- the len- Returns:
- the byte[]
-
unixToWindows
-
replaceAll
Replace all.- Parameters:
target
- the targetname
- the namevalue
- the value
-
replaceAllExt
public static void replaceAllExt(StringBuilder target, String name, String value) throws IOException Replace all. Also check if there are no parameters configured after the parameter name (.e.g $target[2..3]) in target.- Parameters:
target
- the targetname
- the namevalue
- the value- Throws:
IOException
- Signals that an I/O exception has occurred.
-
replaceAllExt
Replace all. Also check if there are no parameters configured after the parameter name (.e.g $target[2..3]) in target.- Parameters:
target
- the targetname
- the namevalue
- the value- Returns:
- the string
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
replaceAll
-
toTime
Converts into time.- Parameters:
time
- the time- Returns:
- the long
-
toTime
-
toXMLValue
-
trimString
-
toHexa
Converts into hexa.- Parameters:
bytes
- the bytes- Returns:
- the string
-
getHash
Return a hash of the string.- Parameters:
bytes
- the bytes- Returns:
- the string
-
toBytes
Converts into bytes.- Parameters:
hexa
- the hexa- Returns:
- the byte[]
- Throws:
NumberFormatException
- the number format exception
-
toBytes
Converts into bytes.- Parameters:
object
- the object- Returns:
- the byte[]
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
toObject
Converts into object.- Parameters:
bytes
- the bytes- Returns:
- the object
- Throws:
IOException
- Signals that an I/O exception has occurred.ClassNotFoundException
- the class not found exception
-
getHostAddress
-
getHostName
-
getParameters
-
getLastMessage
-
getMessage
-
getMessage
-
decode
Decode.- Parameters:
s
- the s- Returns:
- the string
- Throws:
UnsupportedEncodingException
- the unsupported encoding exception
-
getClassName
-
choose
Find the best score to select the line. If no match is found return the first line. /data1/ecmwf/atmos/ ($dataTransfer[target].=DA) /data1/ecmwf/atmos/DA/ ($dataTransfer[target].=DW) /data1/ecmwf/atmos/DW/ ($dataTransfer[target].=EA) /data1/ecmwf/atmos/EA/ ($dataTransfer[target].=EW) /data1/ecmwf/atmos/EW/ ($dataTransfer[target].=S1) /data1/ecmwf/atmos/S1/ ($dataTransfer[target].=M1) /data1/ecmwf/atmos/M1/ ($dataTransfer[target].=T1) /data1/ecmwf/atmos/T1/- Parameters:
options
- the options to choose from.- Returns:
- the selection
- Throws:
Format.DuplicatedChooseScore
- the duplicated choose scoreScriptException
- the script exception
-
choose
The options are in the following format: (.= /readme.txt) standby=yes (== {avhrr_n.*}) standby=never;delay=2h And this method looks for the first line which apply to the selected key. For example, if the key is /etc/readme.txt then the first line will be selected and the method will return "standby=yes". The operator for comparison are the following: ".=" starts with; "==" equals to, if the second part is between {} then it is considered as a regular expression (regex); "=." ends with; "!=" different than.- Parameters:
key
- the key to look for.options
- the options to choose from.- Returns:
- the selection or null if nothing is found
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
objectToString
-
toWMOFormat
-
getCleanPath
-
normalizePath
Normalize path.- Parameters:
path
- the path- Returns:
- the string
- Throws:
FileNotFoundException
- the file not found exception
-
compress
Compress.- Parameters:
str
- the str- Returns:
- the string
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
uncompress
Uncompress.- Parameters:
str
- the str- Returns:
- the string
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
uncompress
Uncompress.- Parameters:
bytes
- the bytes- Returns:
- the string
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
cleanTextContent
-
getFtpList
-
matches
-
extractSearchParameters
Extract search parameters. This method is extracting the parameters in the following form: "param1=value1 param2=space\\ char param3=equal\\=char" (the ' ' and = characters can be escaped)- Parameters:
defaultOptionName
- the default option nameinput
- the input- Returns:
- the map
-
matchesGlobPattern
Matches glob pattern. This method uses the PathMatcher interface with the glob syntax to perform matching based on Unix-style wildcard patterns ('*' and '?').- Parameters:
pattern
- the patterninput
- the input- Returns:
- true, if successful
-