@@ -85,29 +85,15 @@ boolean isTemporary() {
85
85
}
86
86
87
87
File getCacheFile (String fileName ) throws FileNotFoundException {
88
- File f = new File (fileName );
89
- if (isFileRW (f )) {
90
- return f ;
91
- }
92
- // try to find file in cache directory
93
- f = new File (cacheDirectory , f .getName ());
94
- if (isFileRW (f )) {
95
- return f ;
88
+ File file = lookupFile (fileName , false );
89
+ if (file .canWrite ()) {
90
+ return file ;
96
91
}
97
92
throw new FileNotFoundException (fileName );
98
93
}
99
94
100
95
File getHeapFile (String fileName ) throws FileNotFoundException {
101
- File f = new File (fileName );
102
- if (isFileR (f )) {
103
- return f ;
104
- }
105
- // try to find heap dump file next to cache directory
106
- f = new File (cacheDirectory .getParentFile (), f .getName ());
107
- if (isFileR (f )) {
108
- return f ;
109
- }
110
- throw new FileNotFoundException (fileName );
96
+ return lookupFile (fileName , true );
111
97
}
112
98
113
99
void deleteAllCachedFiles () {
@@ -163,6 +149,20 @@ NumberList createNumberList(int idSize) throws IOException {
163
149
return new NumberList (idSize , this );
164
150
}
165
151
152
+ private File lookupFile (String fileName , boolean checkParent ) throws FileNotFoundException {
153
+ File f = new File (fileName );
154
+ if (isFileR (f )) {
155
+ return f ;
156
+ }
157
+ // try to find file next to cache directory or in cache directory
158
+ File dir = checkParent ? cacheDirectory .getParentFile () : cacheDirectory ;
159
+ f = new File (dir , f .getName ());
160
+ if (isFileR (f )) {
161
+ return f ;
162
+ }
163
+ throw new FileNotFoundException (fileName );
164
+ }
165
+
166
166
private static boolean isFileR (File f ) {
167
167
return f .exists () && f .isFile () && f .canRead ();
168
168
}
0 commit comments