comparison artifact-database/src/main/java/de/intevation/artifactdatabase/StringUtils.java @ 80:8447467cef86

Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT). artifacts/trunk@799 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 19 Mar 2010 09:34:40 +0000
parents f69e5b87f05f
children 0f48188a6e02
comparison
equal deleted inserted replaced
79:f69e5b87f05f 80:8447467cef86
1 package de.intevation.artifactdatabase; 1 package de.intevation.artifactdatabase;
2 2
3 import java.io.UnsupportedEncodingException; 3 import java.io.UnsupportedEncodingException;
4 4
5 import java.util.UUID; 5 import java.util.UUID;
6
7 import org.apache.commons.codec.DecoderException;
8
9 import org.apache.commons.codec.binary.Hex;
6 10
7 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
8 12
9 /** 13 /**
10 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> 14 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
11 */ 15 */
12 public final class StringUtils 16 public final class StringUtils
13 { 17 {
14 private static Logger logger = Logger.getLogger(StringUtils.class); 18 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 19
36 public static final String newUUID() { 20 public static final String newUUID() {
37 return UUID.randomUUID().toString(); 21 return UUID.randomUUID().toString();
38 } 22 }
39 23
55 catch (UnsupportedEncodingException usee) { 39 catch (UnsupportedEncodingException usee) {
56 logger.error(usee.getLocalizedMessage(), usee); 40 logger.error(usee.getLocalizedMessage(), usee);
57 return s.getBytes(); 41 return s.getBytes();
58 } 42 }
59 } 43 }
44
45 public static final byte [] decodeHex(String s) {
46 try {
47 return Hex.decodeHex(s.toCharArray());
48 }
49 catch (DecoderException de) {
50 return null;
51 }
52 }
60 } 53 }
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 54 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org