comparison artifact-database/src/main/java/de/intevation/artifactdatabase/StringUtils.java @ 79:f69e5b87f05f

Implementation to export artifacts as xml (applied patch from issue208 by SLT). artifacts/trunk@792 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 16 Mar 2010 16:03:06 +0000
parents
children 8447467cef86
comparison
equal deleted inserted replaced
78:55eefe63a777 79:f69e5b87f05f
1 package de.intevation.artifactdatabase;
2
3 import java.io.UnsupportedEncodingException;
4
5 import java.util.UUID;
6
7 import org.apache.log4j.Logger;
8
9 /**
10 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
11 */
12 public final class StringUtils
13 {
14 private static Logger logger = Logger.getLogger(StringUtils.class);
15
16 private static final char [] HEX = {
17 '0', '1', '2', '3', '4', '5', '6', '7',
18 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
19 };
20
21 private StringUtils() {
22 }
23
24 public static final String toHex(byte [] bytes) {
25 char out [] = new char[bytes.length*2];
26
27 for (int i = 0, j = 0; i < bytes.length; ++i) {
28 byte b = bytes[i];
29 out[j++] = HEX[(b >> 4) & 0xf];
30 out[j++] = HEX[ b & 0xf];
31 }
32
33 return new String(out);
34 }
35
36 public static final String newUUID() {
37 return UUID.randomUUID().toString();
38 }
39
40 public static final boolean checkUUID(String uuid) {
41 try {
42 UUID.fromString(uuid);
43 }
44 catch (IllegalArgumentException iae) {
45 logger.warn(iae.getLocalizedMessage());
46 return false;
47 }
48 return true;
49 }
50
51 public static final byte [] getUTF8Bytes(String s) {
52 try {
53 return s.getBytes("UTF-8");
54 }
55 catch (UnsupportedEncodingException usee) {
56 logger.error(usee.getLocalizedMessage(), usee);
57 return s.getBytes();
58 }
59 }
60 }
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org