KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > transfer > TransferUtils


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * 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 JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.net.URL JavaDoc;
26 import org.apache.log4j.Logger;
27 import org.apache.commons.lang.exception.ExceptionUtils;
28
29
30 /**
31  * A collection of utility methods.
32  */

33 public class TransferUtils {
34
35   // constructors /////////////////////////////////////////////////////////////
36

37   // constants ////////////////////////////////////////////////////////////////
38

39   // classes //////////////////////////////////////////////////////////////////
40

41   // methods //////////////////////////////////////////////////////////////////
42

43   /**
44    * Returns the version number of this release. Version information is stored
45    * in com.methodhead.transfer.version.txt, which is created at build time.
46    */

47   public static String JavaDoc getVersion() {
48
49     String JavaDoc resourceName = "/com/methodhead/transfer/version.txt";
50
51     URL JavaDoc url = TransferUtils.class.getResource( resourceName );
52
53     if ( url == null ) {
54       throw new RuntimeException JavaDoc( "Couldn't get resource for \"" + resourceName + "\"" );
55     }
56
57     byte[] buf = new byte[ 100 ];
58
59     InputStream JavaDoc in = null;
60
61     try {
62       in = url.openStream();
63       int count = in.read( buf );
64       in.close();
65
66       return new String JavaDoc( buf, 0, count );
67     }
68     catch ( IOException JavaDoc e ) {
69       String JavaDoc msg = "Getting version. " + ExceptionUtils.getStackTrace( e );
70       logger_.error( msg );
71       throw new RuntimeException JavaDoc( msg );
72     }
73   }
74
75   // properties ///////////////////////////////////////////////////////////////
76

77   // attributes ///////////////////////////////////////////////////////////////
78

79   private static Logger logger_ = Logger.getLogger( TransferUtils.class );
80 }
81
Popular Tags