01: /*
02: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
03: *
04: * This file is part of TransferCM.
05: *
06: * TransferCM is free software; you can redistribute it and/or modify it under the
07: * terms of the GNU General Public License as published by the Free Software
08: * Foundation; either version 2 of the License, or (at your option) any later
09: * version.
10: *
11: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14: * details.
15: *
16: * You should have received a copy of the GNU General Public License along with
17: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18: * Fifth Floor, Boston, MA 02110-1301 USA
19: */
20:
21: package com.methodhead.transfer;
22:
23: import java.io.IOException;
24: import java.io.InputStream;
25: import java.net.URL;
26: import org.apache.log4j.Logger;
27: import org.apache.commons.lang.exception.ExceptionUtils;
28:
29: /**
30: * A collection of utility methods.
31: */
32: public class TransferUtils {
33:
34: // constructors /////////////////////////////////////////////////////////////
35:
36: // constants ////////////////////////////////////////////////////////////////
37:
38: // classes //////////////////////////////////////////////////////////////////
39:
40: // methods //////////////////////////////////////////////////////////////////
41:
42: /**
43: * Returns the version number of this release. Version information is stored
44: * in com.methodhead.transfer.version.txt, which is created at build time.
45: */
46: public static String getVersion() {
47:
48: String resourceName = "/com/methodhead/transfer/version.txt";
49:
50: URL url = TransferUtils.class.getResource(resourceName);
51:
52: if (url == null) {
53: throw new RuntimeException("Couldn't get resource for \""
54: + resourceName + "\"");
55: }
56:
57: byte[] buf = new byte[100];
58:
59: InputStream in = null;
60:
61: try {
62: in = url.openStream();
63: int count = in.read(buf);
64: in.close();
65:
66: return new String(buf, 0, count);
67: } catch (IOException e) {
68: String msg = "Getting version. "
69: + ExceptionUtils.getStackTrace(e);
70: logger_.error(msg);
71: throw new RuntimeException(msg);
72: }
73: }
74:
75: // properties ///////////////////////////////////////////////////////////////
76:
77: // attributes ///////////////////////////////////////////////////////////////
78:
79: private static Logger logger_ = Logger
80: .getLogger(TransferUtils.class);
81: }
|