Fix comments for af72371db217

This commit is contained in:
Jimmy Shih
2012-01-06 16:06:12 -08:00
parent bb989dbc4c
commit aed9248b35
2 changed files with 14 additions and 21 deletions
@@ -32,7 +32,8 @@ import java.util.TimeZone;
public class FileUtils {
/**
* The maximum Fat32 path length.
* The maximum Fat32 path length. See
* http://www.scribd.com/doc/2187273/FAT32-File-System-Specification
*/
@VisibleForTesting
static final int MAX_FAT32_PATH_LENGTH = 260;
@@ -143,12 +144,11 @@ public class FileUtils {
*/
@VisibleForTesting
String sanitizeFileName(String name) {
StringBuffer buffer = new StringBuffer();
StringBuffer buffer = new StringBuffer(name.length());
for (int i = 0; i < name.length(); i++) {
int codePoint = name.codePointAt(i);
if (codePoint > 127) {
buffer.appendCodePoint(codePoint);
} else if (Character.isLetterOrDigit(name.charAt(i))) {
char character = name.charAt(i);
if (Character.isLetterOrDigit(character) || codePoint > 127 || character == '-') {
buffer.appendCodePoint(codePoint);
} else {
buffer.append("_");
@@ -159,7 +159,7 @@ public class FileUtils {
}
/**
* Truncates the name if necessary thus the filename path length (directory +
* Truncates the name if necessary so the filename path length (directory +
* name + suffix) meets the Fat32 path limit.
*
* @param directory directory
@@ -168,8 +168,7 @@ public class FileUtils {
*/
@VisibleForTesting
String truncateFileName(File directory, String name, String suffix) {
// 1 at the end accounts for the trailing NUL character
// 1 at the end accounts for the FAT32 filename trailing NUL character
int requiredLength = directory.getPath().length() + suffix.length() + 1;
if (name.length() + requiredLength > MAX_FAT32_PATH_LENGTH) {
int limit = MAX_FAT32_PATH_LENGTH - requiredLength;
@@ -31,9 +31,6 @@ import junit.framework.TestCase;
* @author Rodrigo Damazio
*/
public class FileUtilsTest extends TestCase {
private static final String ORIGINAL_NAME = "Swim\10ming-^across: the/ pacific (ocean).";
private static final String SANITIZED_NAME = "Swim_ming_across_the_pacific_ocean_";
private FileUtils fileUtils;
private Set<String> existingFiles;
@@ -66,7 +63,10 @@ public class FileUtilsTest extends TestCase {
}
public void testSanitizeFileName() {
assertEquals(SANITIZED_NAME, fileUtils.sanitizeFileName(ORIGINAL_NAME));
String name = "Swim\10ming-^across: the/ pacific (ocean).您好-привет_";
String expected = "Swim_ming-_across_the_pacific_ocean_您好-привет_";
assertEquals(expected, fileUtils.sanitizeFileName(name));
}
public void testTruncateFileName() {
@@ -78,16 +78,10 @@ public class FileUtilsTest extends TestCase {
}
String nameString = new String(name);
int expectedLength = FileUtils.MAX_FAT32_PATH_LENGTH - directory.getPath().length()
- suffix.length() - 1;
char[] expected = new char[expectedLength];
for (int i = 0; i < expected.length; i++) {
expected[i] = 'a';
}
String expectedString = new String(expected);
String truncated = fileUtils.truncateFileName(directory, nameString, suffix);
assertEquals(expectedString, truncated);
for (int i = 0; i < truncated.length(); i++) {
assertEquals('a', truncated.charAt(i));
}
assertEquals(FileUtils.MAX_FAT32_PATH_LENGTH,
new File(directory, truncated + suffix).getPath().length());
}