ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: svn commit: r486146 - /ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java
Date Tue, 12 Dec 2006 15:46:04 GMT
Doesnt work on my JDK-1.2.1_004


... Compiling Ant Classes
src\main\org\apache\tools\ant\util\StringUtils.java:205: Method matches(java.lang.String)
not found in class java.lang.String.
        if(humanSize.matches(regex)) {
                            ^
src\main\org\apache\tools\ant\util\StringUtils.java:222: Method matches(java.lang.String)
not found in class java.lang.String.
        } else if(humanSize.matches("\\d+")) {



Jan 

>-----Urspr√ľngliche Nachricht-----
>Von: kevj@apache.org [mailto:kevj@apache.org] 
>
>URL: http://svn.apache.org/viewvc?view=rev&rev=486146
>Log:
>- add Human Readable file size 'parsing' method
>
>Modified:
>    ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java
>
>ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java (original)
>+++ ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java 
>+++ Tue Dec 12 05:57:36 2006
>@@ -186,4 +186,43 @@
>         }
>         return b.toString();
>     }
>+    
>+    /**
>+     * Takes a human readable size representation eg 10K
>+     * a long value. Doesn't support 1.1K or other rational values.
>+     * @param humanSize
>+     * @return a long value representation
>+     * @throws Exception
>+     * @since Ant 1.7
>+     */
>+    public static long parseHumanSizes(String humanSize) 
>throws Exception {
>+    	final long KILOBYTE = 1024;
>+    	final long MEGABYTE = KILOBYTE * 1024;
>+    	final long GIGABYTE = MEGABYTE * 1024;
>+    	final long TERABYTE = GIGABYTE * 1024;
>+    	final long PETABYTE = TERABYTE * 1024;
>+    	String regex = "\\d+[K|M|G|T|P]";
>+    	if(humanSize.matches(regex)) {
>+    		char c = humanSize.charAt(humanSize.length()-1);
>+    		long value = 
>Long.valueOf(humanSize.substring(0, humanSize.length()-1)).longValue();
>+    		switch (c) {
>+    			case 'K':
>+    				return value * KILOBYTE;
>+    			case 'M':
>+    				return value * MEGABYTE;
>+    			case 'G':
>+    				return value * GIGABYTE;
>+    			case 'T':
>+    				return value * TERABYTE;
>+    			case 'P':
>+    				return value * PETABYTE;
>+    			default:
>+    				return value;
>+    		}
>+    	} else if(humanSize.matches("\\d+")) {
>+    		return Long.parseLong(humanSize);
>+    	} else {
>+    		throw new Exception("Couldn't parse string: 
>"+humanSize);
>+    	}
>+    }
> }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message