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.
17
17
package org .springframework .core .io ;
18
18
19
19
import java .io .File ;
20
+ import java .io .FileNotFoundException ;
20
21
import java .io .IOException ;
21
22
import java .io .InputStream ;
22
23
import java .net .HttpURLConnection ;
@@ -89,11 +90,11 @@ public boolean exists() {
89
90
try {
90
91
URL url = getURL ();
91
92
if (ResourceUtils .isFileURL (url )) {
92
- // Proceed with file system resolution...
93
+ // Proceed with file system resolution
93
94
return getFile ().exists ();
94
95
}
95
96
else {
96
- // Try a URL connection content-length header...
97
+ // Try a URL connection content-length header
97
98
URLConnection con = url .openConnection ();
98
99
customizeConnection (con );
99
100
HttpURLConnection httpCon =
@@ -133,7 +134,7 @@ public boolean isReadable() {
133
134
try {
134
135
URL url = getURL ();
135
136
if (ResourceUtils .isFileURL (url )) {
136
- // Proceed with file system resolution...
137
+ // Proceed with file system resolution
137
138
File file = getFile ();
138
139
return (file .canRead () && !file .isDirectory ());
139
140
}
@@ -150,11 +151,11 @@ public boolean isReadable() {
150
151
public long contentLength () throws IOException {
151
152
URL url = getURL ();
152
153
if (ResourceUtils .isFileURL (url )) {
153
- // Proceed with file system resolution...
154
+ // Proceed with file system resolution
154
155
return getFile ().length ();
155
156
}
156
157
else {
157
- // Try a URL connection content-length header...
158
+ // Try a URL connection content-length header
158
159
URLConnection con = url .openConnection ();
159
160
customizeConnection (con );
160
161
return con .getContentLength ();
@@ -165,15 +166,18 @@ public long contentLength() throws IOException {
165
166
public long lastModified () throws IOException {
166
167
URL url = getURL ();
167
168
if (ResourceUtils .isFileURL (url ) || ResourceUtils .isJarURL (url )) {
168
- // Proceed with file system resolution...
169
- return super .lastModified ();
170
- }
171
- else {
172
- // Try a URL connection last-modified header...
173
- URLConnection con = url .openConnection ();
174
- customizeConnection (con );
175
- return con .getLastModified ();
169
+ // Proceed with file system resolution
170
+ try {
171
+ return super .lastModified ();
172
+ }
173
+ catch (FileNotFoundException ex ) {
174
+ // Defensively fall back to URL connection check instead
175
+ }
176
176
}
177
+ // Try a URL connection last-modified header
178
+ URLConnection con = url .openConnection ();
179
+ customizeConnection (con );
180
+ return con .getLastModified ();
177
181
}
178
182
179
183
0 commit comments