Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Rostyslav Dudka
*/
final class JarURLConnection extends java.net.JarURLConnection {

Expand Down Expand Up @@ -234,6 +235,21 @@ public Permission getPermission() throws IOException {
return this.permission;
}

@Override
public long getLastModified() {
int defaultTime = 0;
if (this.jarFile == null || this.jarEntryName.isEmpty()) {
return defaultTime;
}
try {
JarEntry entry = getJarEntry();
return (entry == null ? defaultTime : entry.getTime());
}
catch (IOException ex) {
return defaultTime;
}
}

static void setUseFastExceptions(boolean useFastExceptions) {
JarURLConnection.useFastExceptions.set(useFastExceptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*
* @author Andy Wilkinson
* @author Phillip Webb
* @author Rostyslav Dudka
*/
public class JarURLConnectionTests {

Expand Down Expand Up @@ -150,6 +151,14 @@ public void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exceptio
assertThat(url.openConnection().getContentLengthLong()).isEqualTo(1);
}

@Test
public void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
assertThat(connection.getLastModified())
.isEqualTo(connection.getJarEntry().getTime());
}

private String getAbsolutePath() {
return this.rootJarFile.getAbsolutePath().replace('\\', '/');
}
Expand Down