KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > filesys > DiskInfo


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.filesys;
18
19 import org.alfresco.filesys.smb.PCShare;
20
21 /**
22  * SMB disk information class.
23  * <p>
24  * The DiskInfo class contains the details of a remote disk share.
25  */

26 public class DiskInfo
27 {
28
29     // Node/share details
30

31     protected String JavaDoc m_nodename;
32     protected String JavaDoc m_share;
33
34     // Total number of allocation units, available allocation units
35

36     protected long m_totalunits;
37     protected long m_freeunits;
38
39     // Blocks per allocation unit and block size in bytes
40

41     protected long m_blockperunit;
42     protected long m_blocksize;
43
44     /**
45      * Construct a blank disk information object.
46      */

47     public DiskInfo()
48     {
49     }
50
51     /**
52      * Class constructor
53      *
54      * @param shr PCShare
55      * @param totunits int
56      * @param blkunit int
57      * @param blksiz int
58      * @param freeunit int
59      */

60     public DiskInfo(PCShare shr, int totunits, int blkunit, int blksiz, int freeunit)
61     {
62         if (shr != null)
63         {
64             m_nodename = shr.getNodeName();
65             m_share = shr.getShareName();
66         }
67
68         m_totalunits = (long) totunits;
69         m_freeunits = (long) freeunit;
70
71         m_blockperunit = (long) blkunit;
72         m_blocksize = (long) blksiz;
73     }
74
75     /**
76      * Class constructor
77      *
78      * @param shr PCShare
79      * @param totunits long
80      * @param blkunit int
81      * @param blksiz int
82      * @param freeunit long
83      */

84     public DiskInfo(PCShare shr, long totunits, int blkunit, int blksiz, long freeunit)
85     {
86         if (shr != null)
87         {
88             m_nodename = shr.getNodeName();
89             m_share = shr.getShareName();
90         }
91
92         m_totalunits = totunits;
93         m_freeunits = freeunit;
94
95         m_blockperunit = (long) blkunit;
96         m_blocksize = (long) blksiz;
97     }
98
99     /**
100      * Get the block size, in bytes.
101      *
102      * @return Block size in bytes.
103      */

104     public final int getBlockSize()
105     {
106         return (int) m_blocksize;
107     }
108
109     /**
110      * Get the number of blocks per allocation unit.
111      *
112      * @return Number of blocks per allocation unit.
113      */

114     public final int getBlocksPerAllocationUnit()
115     {
116         return (int) m_blockperunit;
117     }
118
119     /**
120      * Get the disk free space in kilobytes.
121      *
122      * @return Remote disk free space in kilobytes.
123      */

124     public final long getDiskFreeSizeKb()
125     {
126         return (((m_freeunits * m_blockperunit) * m_blocksize) / 1024L);
127     }
128
129     /**
130      * Get the disk free space in megabytes.
131      *
132      * @return Remote disk free space in megabytes.
133      */

134     public final long getDiskFreeSizeMb()
135     {
136         return getDiskFreeSizeKb() / 1024L;
137     }
138
139     /**
140      * Get the disk size in kilobytes.
141      *
142      * @return Remote disk size in kilobytes.
143      */

144     public final long getDiskSizeKb()
145     {
146         return (((m_totalunits * m_blockperunit) * m_blocksize) / 1024L);
147     }
148
149     /**
150      * Get the disk size in megabytes.
151      *
152      * @return Remote disk size in megabytes.
153      */

154     public final long getDiskSizeMb()
155     {
156         return (getDiskSizeKb() / 1024L);
157     }
158
159     /**
160      * Get the number of free units on this share.
161      *
162      * @return Number of free units.
163      */

164     public final long getFreeUnits()
165     {
166         return m_freeunits;
167     }
168
169     /**
170      * Return the unit size in bytes
171      *
172      * @return long
173      */

174     public final long getUnitSize()
175     {
176         return m_blockperunit * m_blocksize;
177     }
178
179     /**
180      * Get the node name.
181      *
182      * @return Node name of the remote server.
183      */

184     public final String JavaDoc getNodeName()
185     {
186         return m_nodename;
187     }
188
189     /**
190      * Get the share name.
191      *
192      * @return Remote share name.
193      */

194     public final String JavaDoc getShareName()
195     {
196         return m_share;
197     }
198
199     /**
200      * Get the total number of allocation units.
201      *
202      * @return The total number of allocation units.
203      */

204     public final long getTotalUnits()
205     {
206         return m_totalunits;
207     }
208
209     /**
210      * Return the disk information as a string
211      *
212      * @return String
213      */

214     public String JavaDoc toString()
215     {
216         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
217
218         str.append("[");
219         str.append(getTotalUnits());
220         str.append("/");
221         str.append(getFreeUnits());
222         str.append(",");
223         str.append(getBlockSize());
224         str.append("/");
225         str.append(getBlocksPerAllocationUnit());
226
227         str.append(",");
228         str.append(getDiskSizeMb());
229         str.append("Mb/");
230         str.append(getDiskFreeSizeMb());
231         str.append("Mb");
232
233         str.append("]");
234
235         return str.toString();
236     }
237 }
Popular Tags