11/*
2- * Copyright 2002-2016 the original author or authors.
2+ * Copyright 2002-2017 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1717package org .springframework .core .io ;
1818
1919import java .io .File ;
20+ import java .io .FileNotFoundException ;
2021import java .io .IOException ;
2122import java .io .InputStream ;
2223import java .net .HttpURLConnection ;
@@ -89,11 +90,11 @@ public boolean exists() {
8990 try {
9091 URL url = getURL ();
9192 if (ResourceUtils .isFileURL (url )) {
92- // Proceed with file system resolution...
93+ // Proceed with file system resolution
9394 return getFile ().exists ();
9495 }
9596 else {
96- // Try a URL connection content-length header...
97+ // Try a URL connection content-length header
9798 URLConnection con = url .openConnection ();
9899 customizeConnection (con );
99100 HttpURLConnection httpCon =
@@ -133,7 +134,7 @@ public boolean isReadable() {
133134 try {
134135 URL url = getURL ();
135136 if (ResourceUtils .isFileURL (url )) {
136- // Proceed with file system resolution...
137+ // Proceed with file system resolution
137138 File file = getFile ();
138139 return (file .canRead () && !file .isDirectory ());
139140 }
@@ -150,11 +151,11 @@ public boolean isReadable() {
150151 public long contentLength () throws IOException {
151152 URL url = getURL ();
152153 if (ResourceUtils .isFileURL (url )) {
153- // Proceed with file system resolution...
154+ // Proceed with file system resolution
154155 return getFile ().length ();
155156 }
156157 else {
157- // Try a URL connection content-length header...
158+ // Try a URL connection content-length header
158159 URLConnection con = url .openConnection ();
159160 customizeConnection (con );
160161 return con .getContentLength ();
@@ -165,15 +166,18 @@ public long contentLength() throws IOException {
165166 public long lastModified () throws IOException {
166167 URL url = getURL ();
167168 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+ }
176176 }
177+ // Try a URL connection last-modified header
178+ URLConnection con = url .openConnection ();
179+ customizeConnection (con );
180+ return con .getLastModified ();
177181 }
178182
179183
0 commit comments