KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > util > FileUtils


1 package org.apache.turbine.util;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 /**
20  * Common {@link java.io.File} manipulation routines.
21  *
22  * @author <a HREF="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
23  * @version $Id: FileUtils.java,v 1.4.2.2 2004/05/20 03:16:38 seade Exp $
24  * @deprecated This class will be removed after the 2.3 release. Please
25  * use FileUtils from <a HREF="http://jakarta.apache.org/commons/">commons-io</a>.
26  */

27 public class FileUtils
28 {
29     /**
30      * The number of bytes in a kilobyte.
31      */

32     public static final int ONE_KB = 1024;
33
34     /**
35      * The number of bytes in a megabyte.
36      */

37     public static final int ONE_MB = ONE_KB * ONE_KB;
38
39     /**
40      * The number of bytes in a gigabyte.
41      */

42     public static final int ONE_GB = ONE_KB * ONE_MB;
43
44     /**
45      * Returns a human-readable version of the file size (original is in
46      * bytes).
47      *
48      * @param size The number of bytes.
49      * @return A human-readable display value (includes units).
50      */

51     public static String JavaDoc byteCountToDisplaySize(int size)
52     {
53         String JavaDoc displaySize;
54
55         if (size / ONE_GB > 0)
56         {
57             displaySize = String.valueOf(size / ONE_GB) + " GB";
58         }
59         else if (size / ONE_MB > 0)
60         {
61             displaySize = String.valueOf(size / ONE_MB) + " MB";
62         }
63         else if (size / ONE_KB > 0)
64         {
65             displaySize = String.valueOf(size / ONE_KB) + " kB";
66         }
67         else
68         {
69             displaySize = String.valueOf(size) + " bytes";
70         }
71
72         return displaySize;
73     }
74 }
75
Popular Tags