1 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 33 public class TransferUtils { 34 35 37 39 41 43 47 public static String getVersion() { 48 49 String resourceName = "/com/methodhead/transfer/version.txt"; 50 51 URL url = TransferUtils.class.getResource( resourceName ); 52 53 if ( url == null ) { 54 throw new RuntimeException ( "Couldn't get resource for \"" + 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 } 68 catch ( IOException e ) { 69 String msg = "Getting version. " + ExceptionUtils.getStackTrace( e ); 70 logger_.error( msg ); 71 throw new RuntimeException ( msg ); 72 } 73 } 74 75 77 79 private static Logger logger_ = Logger.getLogger( TransferUtils.class ); 80 } 81 | Popular Tags |