2424import java .io .InputStream ;
2525import java .net .URL ;
2626import java .net .URLConnection ;
27+ import java .util .Optional ;
2728
2829import org .jooby .Asset ;
2930import org .jooby .MediaType ;
@@ -36,12 +37,17 @@ class URLAsset implements Asset {
3637
3738 private MediaType mediaType ;
3839
39- private long lastModified ;
40+ private long lastModified = -1 ;
41+
42+ private long length = -1 ;
4043
4144 public URLAsset (final URL url , final MediaType mediaType ) throws IOException {
4245 this .url = requireNonNull (url , "An url is required." );
4346 this .mediaType = requireNonNull (mediaType , "A mediaType is required." );
44- this .lastModified = lastModified (url );
47+ Optional .ofNullable (lastModified (url )).ifPresent (md -> {
48+ this .length = md [0 ];
49+ this .lastModified = md [1 ];
50+ });
4551 }
4652
4753 @ Override
@@ -51,6 +57,11 @@ public String name() {
5157 return path .substring (slash + 1 );
5258 }
5359
60+ @ Override
61+ public long length () {
62+ return length ;
63+ }
64+
5465 @ Override
5566 public InputStream stream () throws IOException {
5667 return url .openStream ();
@@ -71,13 +82,13 @@ public String toString() {
7182 return name () + "(" + type () + ")" ;
7283 }
7384
74- private static long lastModified (final URL resource ) throws IOException {
85+ private static long [] lastModified (final URL resource ) throws IOException {
7586 URLConnection uc = null ;
7687 try {
7788 uc = resource .openConnection ();
78- return uc .getLastModified ();
89+ return new long []{ uc .getContentLengthLong (), uc . getLastModified () } ;
7990 } catch (IOException ex ) {
80- return - 1 ;
91+ return null ;
8192 } finally {
8293 if (uc != null ) {
8394 // http://stackoverflow.com/questions/2057351/how-do-i-get-the-last-modification-time-of
0 commit comments