1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .io .File ;
20
20
import java .io .FileInputStream ;
21
+ import java .io .FileNotFoundException ;
21
22
import java .io .IOException ;
22
23
import java .io .InputStream ;
23
24
import java .net .HttpURLConnection ;
@@ -139,11 +140,11 @@ public boolean exists() {
139
140
try {
140
141
URL url = getURL ();
141
142
if (ResourceUtils .isFileURL (url )) {
142
- // Proceed with file system resolution...
143
+ // Proceed with file system resolution
143
144
return getFile ().exists ();
144
145
}
145
146
else {
146
- // Try a URL connection content-length header...
147
+ // Try a URL connection content-length header
147
148
URLConnection con = url .openConnection ();
148
149
customizeConnection (con );
149
150
HttpURLConnection httpCon =
@@ -183,7 +184,7 @@ public boolean isReadable() {
183
184
try {
184
185
URL url = getURL ();
185
186
if (ResourceUtils .isFileURL (url )) {
186
- // Proceed with file system resolution...
187
+ // Proceed with file system resolution
187
188
File file = getFile ();
188
189
return (file .canRead () && !file .isDirectory ());
189
190
}
@@ -200,11 +201,11 @@ public boolean isReadable() {
200
201
public long contentLength () throws IOException {
201
202
URL url = getURL ();
202
203
if (ResourceUtils .isFileURL (url )) {
203
- // Proceed with file system resolution...
204
+ // Proceed with file system resolution
204
205
return getFile ().length ();
205
206
}
206
207
else {
207
- // Try a URL connection content-length header...
208
+ // Try a URL connection content-length header
208
209
URLConnection con = url .openConnection ();
209
210
customizeConnection (con );
210
211
return con .getContentLength ();
@@ -215,15 +216,18 @@ public long contentLength() throws IOException {
215
216
public long lastModified () throws IOException {
216
217
URL url = getURL ();
217
218
if (ResourceUtils .isFileURL (url ) || ResourceUtils .isJarURL (url )) {
218
- // Proceed with file system resolution...
219
- return super .lastModified ();
220
- }
221
- else {
222
- // Try a URL connection last-modified header...
223
- URLConnection con = url .openConnection ();
224
- customizeConnection (con );
225
- return con .getLastModified ();
219
+ // Proceed with file system resolution
220
+ try {
221
+ return super .lastModified ();
222
+ }
223
+ catch (FileNotFoundException ex ) {
224
+ // Defensively fall back to URL connection check instead
225
+ }
226
226
}
227
+ // Try a URL connection last-modified header
228
+ URLConnection con = url .openConnection ();
229
+ customizeConnection (con );
230
+ return con .getLastModified ();
227
231
}
228
232
229
233
0 commit comments