Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/StringUtils.java @ 87:0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
artifacts/trunk@839 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 11:40:28 +0000 |
parents | 8447467cef86 |
children | 933bbc9fc11f |
comparison
equal
deleted
inserted
replaced
86:b2e0cb83631c | 87:0f48188a6e02 |
---|---|
9 import org.apache.commons.codec.binary.Hex; | 9 import org.apache.commons.codec.binary.Hex; |
10 | 10 |
11 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
12 | 12 |
13 /** | 13 /** |
14 * Commonly used string functions. | |
15 * | |
14 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
15 */ | 17 */ |
16 public final class StringUtils | 18 public final class StringUtils |
17 { | 19 { |
18 private static Logger logger = Logger.getLogger(StringUtils.class); | 20 private static Logger logger = Logger.getLogger(StringUtils.class); |
19 | 21 |
22 /** | |
23 * Generated a random UUIDv4 in form of a string. | |
24 * @return the UUID | |
25 */ | |
20 public static final String newUUID() { | 26 public static final String newUUID() { |
21 return UUID.randomUUID().toString(); | 27 return UUID.randomUUID().toString(); |
22 } | 28 } |
23 | 29 |
30 /** | |
31 * Checks if a given string is a valid UUID. | |
32 * @param uuid The string to test. | |
33 * @return true if the string is a valid UUID else false. | |
34 */ | |
24 public static final boolean checkUUID(String uuid) { | 35 public static final boolean checkUUID(String uuid) { |
25 try { | 36 try { |
26 UUID.fromString(uuid); | 37 UUID.fromString(uuid); |
27 } | 38 } |
28 catch (IllegalArgumentException iae) { | 39 catch (IllegalArgumentException iae) { |
30 return false; | 41 return false; |
31 } | 42 } |
32 return true; | 43 return true; |
33 } | 44 } |
34 | 45 |
46 /** | |
47 * Returns the UTF-8 byte array representation of a given string. | |
48 * @param s The string to be transformed. | |
49 * @return The byte array representation. | |
50 */ | |
35 public static final byte [] getUTF8Bytes(String s) { | 51 public static final byte [] getUTF8Bytes(String s) { |
36 try { | 52 try { |
37 return s.getBytes("UTF-8"); | 53 return s.getBytes("UTF-8"); |
38 } | 54 } |
39 catch (UnsupportedEncodingException usee) { | 55 catch (UnsupportedEncodingException usee) { |
40 logger.error(usee.getLocalizedMessage(), usee); | 56 logger.error(usee.getLocalizedMessage(), usee); |
41 return s.getBytes(); | 57 return s.getBytes(); |
42 } | 58 } |
43 } | 59 } |
44 | 60 |
61 /** | |
62 * Tries to convert a Base64 encoded string into the | |
63 * corresponing byte array. | |
64 * @param s The Base64 encoded string | |
65 * @return The byte array representation or null if | |
66 * an decoding error occurs. | |
67 */ | |
45 public static final byte [] decodeHex(String s) { | 68 public static final byte [] decodeHex(String s) { |
46 try { | 69 try { |
47 return Hex.decodeHex(s.toCharArray()); | 70 return Hex.decodeHex(s.toCharArray()); |
48 } | 71 } |
49 catch (DecoderException de) { | 72 catch (DecoderException de) { |