forked from marceloverdijk/lesscss-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResource.java
More file actions
58 lines (48 loc) · 1.47 KB
/
Copy pathHttpResource.java
File metadata and controls
58 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.lesscss;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
public class HttpResource implements Resource {
URI url;
public HttpResource(String url) throws URISyntaxException {
this.url = new URI( url );
}
public HttpResource(URI url) {
this.url = url;
}
public boolean exists() {
try {
URL u = url.toURL();
URLConnection connection = u.openConnection();
connection.connect();
return true;
} catch (IOException e) {
return false;
}
}
public long lastModified() {
try {
URL u = url.toURL();
URLConnection connection = u.openConnection();
return connection.getLastModified();
} catch( IOException e ) {
return 0;
}
}
public InputStream getInputStream() throws IOException {
return url.toURL().openStream();
}
public Resource createRelative(String relativeResourcePath) throws IOException {
try {
return new HttpResource(url.resolve(new URI(relativeResourcePath)));
} catch (URISyntaxException e) {
throw (IOException)new IOException( "Could not resolve " + url + " against " + relativeResourcePath ).initCause(e);
}
}
public String getName() {
return url.toASCIIString();
}
}