|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.claudio.lib.Util
public class Util
Copyright (C) 2004-2008 Claudio Nieder <private@claudio.ch>, CH-8610 Uster
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Field Summary | |
---|---|
static long |
day
Number of milliseconds in a day. |
static long |
hour
Number of milliseconds in a hour. |
static java.text.DateFormat |
isoDate
Time in ISO format with just the date, e.g. |
static java.text.DateFormat |
isoDateTime
Time in ISO format with seconds resolution, e.g. |
static java.text.DateFormat |
isoDateTimeMin
Time in ISO format with minute resolution, e.g. |
static long |
minute
Number of milliseconds in a minute. |
static long |
second
Number of milliseconds in a second. |
static long |
week
Number of milliseconds in a week. |
Method Summary | |
---|---|
static byte[] |
base64ToByte(java.lang.String data)
From a base 64 representation, returns the corresponding byte[] |
static java.lang.String |
bytes2asc(byte[] bytes,
int offset,
int length)
Return an ascii string containing just the visible characters of the byte array. |
static java.lang.String |
byteToBase64(byte[] data)
From a byte[] returns a base 64 representation |
static void |
delay(long ms)
Delay procedure which calls sleep ignoring any interrupt. |
static java.lang.String |
dumpBytes(byte[] bytes)
Return a hex and text dump of the byte array |
static int |
exec(java.lang.String[] command,
java.lang.String input,
java.lang.StringBuffer output,
int outputSize,
long timeout)
Execute a unix command with a timeout. |
static byte[] |
getHash(int iterations,
java.lang.String password,
byte[] salt)
From a password, a number of iterations and a salt, returns the corresponding digest |
static java.lang.String |
groupThree(java.lang.String number)
Reformat string so that e.g. |
static java.lang.String |
join(java.lang.String separator,
java.util.List<?> parts)
Join all elements of a string list to one string with separator in between each element. |
static java.lang.String |
join(java.lang.String separator,
java.lang.Object[] parts)
Join all elements of a string array to one string with separator in between each element. |
static java.lang.String |
joinByteArray(java.lang.String separator,
java.util.List<byte[]> parts)
Join all elements of a string list to one string with separator in between each element. |
static java.lang.Object |
loadMessageClass(java.lang.Class<?> baseClass,
java.util.Locale locale)
Give a base class and a locale this method tries to find a class most appropriate. |
static void |
main(java.lang.String[] args)
Print license. |
static byte[] |
readAndAdjustImage(java.io.File pictureFile,
int maxDimension,
boolean highQuality)
Reads a picture from a file and converts it to a jpeg byte array. |
static java.net.URI |
relativeURI(java.net.URI reference,
java.net.URI target)
Create a relative URI if possible. |
static void |
replaceIfChanged(java.io.File newFile,
java.io.File oldFile)
This function is intended to help to modify a file "only if needed". |
static java.net.URL |
stringToURL(java.lang.String s)
Creat an URL object out of a string without throwing an exception. |
static java.net.URL |
stringToURL(java.net.URL base,
java.lang.String s)
Creat an URL object out of a base url and a string "relative" to the base url without throwing an exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.text.DateFormat isoDate
public static final java.text.DateFormat isoDateTime
public static final java.text.DateFormat isoDateTimeMin
public static final long second
public static final long minute
public static final long hour
public static final long day
public static final long week
Method Detail |
---|
public static java.lang.String bytes2asc(byte[] bytes, int offset, int length)
bytes
- byte arrayoffset
- startlength
- length
public static java.lang.String dumpBytes(byte[] bytes)
bytes
- byte array
public static java.lang.String join(java.lang.String separator, java.lang.Object[] parts)
separator
- parts
-
public static java.lang.String join(java.lang.String separator, java.util.List<?> parts)
separator
- parts
-
public static java.lang.String joinByteArray(java.lang.String separator, java.util.List<byte[]> parts)
separator
- parts
-
public static void delay(long ms)
ms
- Miliseconds to waitpublic static int exec(java.lang.String[] command, java.lang.String input, java.lang.StringBuffer output, int outputSize, long timeout)
Note: This method creates a temporary buffer of the size supplied by outputSize.
command
- Command to execute with all argumentsinput
- If non-null this content is supplied to the stdin of the
process.output
- Buffer to which stdout and stderr are written.outputSize
- Maximal number of characters needed of the output.timeout
- maximum execution time if a positive value.
public static java.net.URL stringToURL(java.lang.String s)
s
- url in string
public static java.net.URL stringToURL(java.net.URL base, java.lang.String s)
base
- bases
- path relative to base url
public static java.net.URI relativeURI(java.net.URI reference, java.net.URI target)
reference
- target
-
public static byte[] readAndAdjustImage(java.io.File pictureFile, int maxDimension, boolean highQuality) throws java.io.IOException
pictureFile
- file containing a picturemaxDimension
- maximal height or lengthhighQuality
- if true a better but slower algorithm is used to scale
java.io.IOException
public static java.lang.String byteToBase64(byte[] data)
data
- byte[]
public static byte[] base64ToByte(java.lang.String data) throws java.io.IOException
data
- String The base64 representation
java.io.IOException
public static byte[] getHash(int iterations, java.lang.String password, byte[] salt) throws java.security.NoSuchAlgorithmException
iterations
- int The number of iterations of the algorithmpassword
- String The password to encryptsalt
- byte[] The salt
java.security.NoSuchAlgorithmException
- If the algorithm doesn't existpublic static java.lang.Object loadMessageClass(java.lang.Class<?> baseClass, java.util.Locale locale)
Only classes which are actually subclasses of the base class are taken. I.e. if the base class is example.Messages and the locale is de_CH and a class example.Messages_de_CH exists, but is not a subclass of example.Messages, then it is ignored.
locale
- baseClass
- Base message class
public static final void replaceIfChanged(java.io.File newFile, java.io.File oldFile)
Such an approach makes sense, if one does not want to blindly overwrite a file, but keep the existing one with existing time stamp if the newly created file does not introduce any change.
Note: Assumes that the new file was created in the same directory as the old one, so that rename will always work.
Note: Does not guard against modifications of the file between check and rename.
newFile
- The temporary new fileoldFile
- The file which shall be replaced by the temporary onepublic static java.lang.String groupThree(java.lang.String number)
number
- non-negative without leading or trailing spaces
public static void main(java.lang.String[] args)
args
- ignored
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |