You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2005/09/26 22:39:50 UTC
svn commit: r291741 - in /jakarta/commons/proper/io/trunk/src:
java/org/apache/commons/io/FileSystemUtils.java
test/org/apache/commons/io/FileSystemUtilsTestCase.java
Author: scolebourne
Date: Mon Sep 26 13:39:45 2005
New Revision: 291741
URL: http://svn.apache.org/viewcvs?rev=291741&view=rev
Log:
Rename the free space method to be commons-io like
Modified:
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java
jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java
Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java?rev=291741&r1=291740&r2=291741&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java (original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java Mon Sep 26 13:39:45 2005
@@ -94,12 +94,13 @@
super();
}
+ //-----------------------------------------------------------------------
/**
* Returns the free space on a drive or volume in a cross-platform manner.
* Note that some OS's are NOT currently supported, including OS/390.
* <pre>
- * FileSystemUtils.getFreeSpace("C:"); // Windows
- * FileSystemUtils.getFreeSpace("/volume"); // *nix
+ * FileSystemUtils.freeSpace("C:"); // Windows
+ * FileSystemUtils.freeSpace("/volume"); // *nix
* </pre>
* The free space is calculated via the command line.
* It uses 'dir /-c' on Windows and 'df' on *nix.
@@ -110,16 +111,16 @@
* @throws IllegalStateException if an error occurred in initialisation
* @throws IOException if an error occurs when finding the free space
*/
- public static long getFreeSpace(String path) throws IOException {
- return INSTANCE.getFreeSpaceOS(path, OS);
+ public static long freeSpace(String path) throws IOException {
+ return INSTANCE.freeSpaceOS(path, OS);
}
/**
* Returns the free space on a drive or volume in a cross-platform manner.
* Note that some OS's are NOT currently supported, including OS/390.
* <pre>
- * FileSystemUtils.getFreeSpace("C:"); // Windows
- * FileSystemUtils.getFreeSpace("/volume"); // *nix
+ * FileSystemUtils.freeSpace("C:"); // Windows
+ * FileSystemUtils.freeSpace("/volume"); // *nix
* </pre>
* The free space is calculated via the command line.
* It uses 'dir /-c' on Windows and 'df' on *nix.
@@ -130,15 +131,15 @@
* @throws IllegalStateException if an error occurred in initialisation
* @throws IOException if an error occurs when finding the free space
*/
- protected long getFreeSpaceOS(String path, int os) throws IOException {
+ long freeSpaceOS(String path, int os) throws IOException {
if (path == null) {
throw new IllegalArgumentException("Path must not be empty");
}
switch (os) {
case WINDOWS:
- return getFreeSpaceWindows(path);
+ return freeSpaceWindows(path);
case UNIX:
- return getFreeSpaceUnix(path);
+ return freeSpaceUnix(path);
case OTHER:
throw new IllegalStateException("Unsupported operating system");
default:
@@ -154,7 +155,7 @@
* @return the amount of free drive space on the drive
* @throws IOException if an error occurs
*/
- protected long getFreeSpaceWindows(String path) throws IOException {
+ long freeSpaceWindows(String path) throws IOException {
path = FilenameUtils.normalize(path);
if (path.length() > 2 && path.charAt(1) == ':') {
path = path.substring(0, 2); // seems to make it work
@@ -245,7 +246,7 @@
* @return the amount of free drive space on the volume
* @throws IOException if an error occurs
*/
- protected long getFreeSpaceUnix(String path) throws IOException {
+ long freeSpaceUnix(String path) throws IOException {
if (path.length() == 0) {
throw new IllegalArgumentException("Path must not be empty");
}
@@ -315,7 +316,7 @@
* @param params the command parameters
* @return a reader
*/
- protected BufferedReader openProcessStream(String[] params) throws IOException {
+ BufferedReader openProcessStream(String[] params) throws IOException {
Process proc = Runtime.getRuntime().exec(params);
return new BufferedReader(
new InputStreamReader(proc.getInputStream()));
Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java?rev=291741&r1=291740&r2=291741&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java (original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java Mon Sep 26 13:39:45 2005
@@ -62,9 +62,9 @@
public void testGetFreeSpace_String() throws Exception {
// test coverage, as we can't check value
if (File.separatorChar == '/') {
- assertEquals(true, FileSystemUtils.getFreeSpace("/") > 0);
+ assertEquals(true, FileSystemUtils.freeSpace("/") > 0);
} else {
- assertEquals(true, FileSystemUtils.getFreeSpace("") > 0);
+ assertEquals(true, FileSystemUtils.freeSpace("") > 0);
}
}
@@ -72,7 +72,7 @@
public void testGetFreeSpaceOS_String_NullPath() throws Exception {
FileSystemUtils fsu = new FileSystemUtils();
try {
- fsu.getFreeSpaceOS(null, 1);
+ fsu.freeSpaceOS(null, 1);
fail();
} catch (IllegalArgumentException ex) {}
}
@@ -80,7 +80,7 @@
public void testGetFreeSpaceOS_String_InitError() throws Exception {
FileSystemUtils fsu = new FileSystemUtils();
try {
- fsu.getFreeSpaceOS("", -1);
+ fsu.freeSpaceOS("", -1);
fail();
} catch (IllegalStateException ex) {}
}
@@ -88,27 +88,27 @@
public void testGetFreeSpaceOS_String_Other() throws Exception {
FileSystemUtils fsu = new FileSystemUtils();
try {
- fsu.getFreeSpaceOS("", 0);
+ fsu.freeSpaceOS("", 0);
fail();
} catch (IllegalStateException ex) {}
}
public void testGetFreeSpaceOS_String_Windows() throws Exception {
FileSystemUtils fsu = new FileSystemUtils() {
- protected long getFreeSpaceWindows(String path) throws IOException {
+ protected long freeSpaceWindows(String path) throws IOException {
return 12345L;
}
};
- assertEquals(12345L, fsu.getFreeSpaceOS("", 1));
+ assertEquals(12345L, fsu.freeSpaceOS("", 1));
}
public void testGetFreeSpaceOS_String_Unix() throws Exception {
FileSystemUtils fsu = new FileSystemUtils() {
- protected long getFreeSpaceUnix(String path) throws IOException {
+ protected long freeSpaceUnix(String path) throws IOException {
return 12345L;
}
};
- assertEquals(12345L, fsu.getFreeSpaceOS("", 2));
+ assertEquals(12345L, fsu.freeSpaceOS("", 2));
}
//-----------------------------------------------------------------------
@@ -132,7 +132,7 @@
return new BufferedReader(reader);
}
};
- assertEquals(41411551232L, fsu.getFreeSpaceWindows(""));
+ assertEquals(41411551232L, fsu.freeSpaceWindows(""));
}
public void testGetFreeSpaceWindows_String_NormalResponse() throws Exception {
@@ -155,7 +155,7 @@
return new BufferedReader(reader);
}
};
- assertEquals(41411551232L, fsu.getFreeSpaceWindows("C:"));
+ assertEquals(41411551232L, fsu.freeSpaceWindows("C:"));
}
public void testGetFreeSpaceWindows_String_StripDrive() throws Exception {
@@ -178,7 +178,7 @@
return new BufferedReader(reader);
}
};
- assertEquals(41411551232L, fsu.getFreeSpaceWindows("C:\\somedir"));
+ assertEquals(41411551232L, fsu.freeSpaceWindows("C:\\somedir"));
}
public void testGetFreeSpaceWindows_String_EmptyResponse() throws Exception {
@@ -190,7 +190,7 @@
}
};
try {
- fsu.getFreeSpaceWindows("C:");
+ fsu.freeSpaceWindows("C:");
fail();
} catch (IOException ex) {}
}
@@ -207,7 +207,7 @@
}
};
try {
- fsu.getFreeSpaceUnix("");
+ fsu.freeSpaceUnix("");
fail();
} catch (IllegalArgumentException ex) {}
}
@@ -222,7 +222,7 @@
return new BufferedReader(reader);
}
};
- assertEquals(1472504L, fsu.getFreeSpaceUnix("/home/users/s"));
+ assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s"));
}
public void testGetFreeSpaceUnix_String_LongResponse() throws Exception {
@@ -236,7 +236,7 @@
return new BufferedReader(reader);
}
};
- assertEquals(1472504L, fsu.getFreeSpaceUnix("/home/users/s"));
+ assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s"));
}
public void testGetFreeSpaceUnix_String_EmptyResponse() throws Exception {
@@ -248,7 +248,7 @@
}
};
try {
- fsu.getFreeSpaceUnix("/home/users/s");
+ fsu.freeSpaceUnix("/home/users/s");
fail();
} catch (IOException ex) {}
}
@@ -264,7 +264,7 @@
}
};
try {
- fsu.getFreeSpaceUnix("/home/users/s");
+ fsu.freeSpaceUnix("/home/users/s");
fail();
} catch (IOException ex) {}
}
@@ -280,7 +280,7 @@
}
};
try {
- fsu.getFreeSpaceUnix("/home/users/s");
+ fsu.freeSpaceUnix("/home/users/s");
fail();
} catch (IOException ex) {}
}
@@ -296,7 +296,7 @@
}
};
try {
- fsu.getFreeSpaceUnix("/home/users/s");
+ fsu.freeSpaceUnix("/home/users/s");
fail();
} catch (IOException ex) {}
}
@@ -312,7 +312,7 @@
}
};
try {
- fsu.getFreeSpaceUnix("/home/users/s");
+ fsu.freeSpaceUnix("/home/users/s");
fail();
} catch (IOException ex) {}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org