1 package org.apache.turbine.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 264148 2005-08-29 14:21:04Z henning $
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 byteCountToDisplaySize(int size)
52 {
53 String 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 }