提交 72a556e8 authored 作者: Thomas Mueller's avatar Thomas Mueller

Make FindBugs happy

上级 f7352ac0
...@@ -25,7 +25,7 @@ public class FileObjectMemory implements FileObject { ...@@ -25,7 +25,7 @@ public class FileObjectMemory implements FileObject {
private static final int BLOCK_SIZE_MASK = BLOCK_SIZE - 1; private static final int BLOCK_SIZE_MASK = BLOCK_SIZE - 1;
private static final CompressLZF LZF = new CompressLZF(); private static final CompressLZF LZF = new CompressLZF();
private static final byte[] BUFFER = new byte[BLOCK_SIZE * 2]; private static final byte[] BUFFER = new byte[BLOCK_SIZE * 2];
private static byte[] cachedCompressedEmptyBlock; private static final byte[] COMPRESSED_EMPTY_BLOCK;
//## Java 1.4 begin ## //## Java 1.4 begin ##
private static final Cache<CompressItem, CompressItem> COMPRESS_LATER = new Cache<CompressItem, CompressItem>(CACHE_SIZE); private static final Cache<CompressItem, CompressItem> COMPRESS_LATER = new Cache<CompressItem, CompressItem>(CACHE_SIZE);
...@@ -38,6 +38,13 @@ public class FileObjectMemory implements FileObject { ...@@ -38,6 +38,13 @@ public class FileObjectMemory implements FileObject {
private byte[][] data; private byte[][] data;
private long lastModified; private long lastModified;
static {
byte[] n = new byte[BLOCK_SIZE];
int len = LZF.compress(n, BLOCK_SIZE, BUFFER, 0);
COMPRESSED_EMPTY_BLOCK = new byte[len];
System.arraycopy(BUFFER, 0, COMPRESSED_EMPTY_BLOCK, 0, len);
}
/** /**
* This small cache compresses the data if an element leaves the cache. * This small cache compresses the data if an element leaves the cache.
*/ */
...@@ -77,7 +84,7 @@ public class FileObjectMemory implements FileObject { ...@@ -77,7 +84,7 @@ public class FileObjectMemory implements FileObject {
int page; int page;
public int hashCode() { public int hashCode() {
return data.hashCode() ^ page; return page;
} }
public boolean equals(Object o) { public boolean equals(Object o) {
...@@ -138,16 +145,6 @@ public class FileObjectMemory implements FileObject { ...@@ -138,16 +145,6 @@ public class FileObjectMemory implements FileObject {
} }
} }
static byte[] getCompressedEmptyBlock() {
if (cachedCompressedEmptyBlock == null) {
byte[] n = new byte[BLOCK_SIZE];
int len = LZF.compress(n, BLOCK_SIZE, BUFFER, 0);
cachedCompressedEmptyBlock = new byte[len];
System.arraycopy(BUFFER, 0, cachedCompressedEmptyBlock, 0, len);
}
return cachedCompressedEmptyBlock;
}
private void touch() { private void touch() {
lastModified = System.currentTimeMillis(); lastModified = System.currentTimeMillis();
} }
...@@ -190,7 +187,7 @@ public class FileObjectMemory implements FileObject { ...@@ -190,7 +187,7 @@ public class FileObjectMemory implements FileObject {
byte[][] n = new byte[blocks][]; byte[][] n = new byte[blocks][];
System.arraycopy(data, 0, n, 0, Math.min(data.length, n.length)); System.arraycopy(data, 0, n, 0, Math.min(data.length, n.length));
for (int i = data.length; i < blocks; i++) { for (int i = data.length; i < blocks; i++) {
n[i] = getCompressedEmptyBlock(); n[i] = COMPRESSED_EMPTY_BLOCK;
} }
data = n; data = n;
} }
......
...@@ -167,7 +167,7 @@ public class FileSystemDisk extends FileSystem { ...@@ -167,7 +167,7 @@ public class FileSystemDisk extends FileSystem {
dir = null; dir = null;
} else { } else {
dir = new File(name).getAbsoluteFile().getParentFile(); dir = new File(name).getAbsoluteFile().getParentFile();
dir.mkdirs(); FileUtils.mkdirs(dir);
} }
if (prefix.length() < 3) { if (prefix.length() < 3) {
prefix += "0"; prefix += "0";
...@@ -304,7 +304,7 @@ public class FileSystemDisk extends FileSystem { ...@@ -304,7 +304,7 @@ public class FileSystemDisk extends FileSystem {
} }
File dir = new File(parent); File dir = new File(parent);
for (int i = 0; i < SysProperties.MAX_FILE_RETRY; i++) { for (int i = 0; i < SysProperties.MAX_FILE_RETRY; i++) {
if (dir.exists() || dir.mkdirs()) { if ((dir.exists() && dir.isDirectory()) || dir.mkdirs()) {
return; return;
} }
wait(i); wait(i);
......
...@@ -27,6 +27,29 @@ public class FileUtils { ...@@ -27,6 +27,29 @@ public class FileUtils {
// utility class // utility class
} }
/**
* Create the directory and all parent directories if required.
*
* @param directory the directory
* @throws IOException
*/
public static void mkdirs(File directory) throws IOException {
// loop, to deal with race conditions (if another thread creates or
// deletes the same directory at the same time).
for (int i = 0; i < 5; i++) {
if (directory.exists()) {
if (directory.isDirectory()) {
return;
}
throw new IOException("Could not create directory, because a file with the same name already exists: " + directory.getAbsolutePath());
}
if (directory.mkdirs()) {
return;
}
}
throw new IOException("Could not create directory: " + directory.getAbsolutePath());
}
/** /**
* Change the length of the file. * Change the length of the file.
* *
......
...@@ -60,7 +60,7 @@ public class CompareMode { ...@@ -60,7 +60,7 @@ public class CompareMode {
* @param strength the collation strength * @param strength the collation strength
* @return the compare mode * @return the compare mode
*/ */
public static CompareMode getInstance(String name, int strength) { public static synchronized CompareMode getInstance(String name, int strength) {
if (lastUsed != null) { if (lastUsed != null) {
if (StringUtils.equals(lastUsed.name, name)) { if (StringUtils.equals(lastUsed.name, name)) {
if (lastUsed.strength == strength) { if (lastUsed.strength == strength) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论