View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.jdiagnose.library.io;
17  
18  import org.jdiagnose.DiagnosticUnit;
19  
20  /***
21   * @author jmccrindle
22   */
23  public class Win32DiskSpaceDiagnostic extends DiagnosticUnit {
24      
25      private long minimumFreeSpaceBytes = 0L;
26      private String drive = null;
27      
28      public void diagnoseFreeSpace() {
29          assertNotNull("drive property must be set", drive);
30          String os = System.getProperty("os.name").toLowerCase();
31          assertTrue("Operating System not part of the Microsoft Windows Family (" + os + ")", 
32                  (os.indexOf("windows 9") > -1) 
33                  || (os.indexOf("nt") > -1) 
34                  || (os.indexOf("windows 2000") > -1)
35                  || (os.indexOf("windows xp") > -1));
36          long diskFreeSpace = Win32Utils.getDiskFreeSpace(drive);
37          assertTrue("Free Disk Space is less than minimum space required (" + diskFreeSpace + ")", diskFreeSpace > minimumFreeSpaceBytes);
38      }
39  
40      /***
41       * @return Returns the drive.
42       */
43      public String getDrive() {
44          return drive;
45      }
46      /***
47       * @param drive The drive to set.
48       */
49      public void setDrive(String drive) {
50          this.drive = drive;
51      }
52      /***
53       * @return Returns the minimumFreeSpaceBytes.
54       */
55      public long getMinimumFreeSpaceBytes() {
56          return minimumFreeSpaceBytes;
57      }
58      /***
59       * @param minimumFreeSpaceBytes The minimumFreeSpaceBytes to set.
60       */
61      public void setMinimumFreeSpaceBytes(long minimumFreeSpaceBytes) {
62          this.minimumFreeSpaceBytes = minimumFreeSpaceBytes;
63      }
64  }