|
|
@@ -18,7 +18,6 @@ import java.net.HttpURLConnection;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URI;
|
|
|
import java.net.URL;
|
|
|
-import java.net.URLConnection;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.nio.file.Path;
|
|
|
import java.time.Instant;
|
|
|
@@ -34,7 +33,6 @@ import net.ranides.assira.io.uri.URIHandle;
|
|
|
import net.ranides.assira.io.uri.URIHandler;
|
|
|
import net.ranides.assira.text.Charsets;
|
|
|
import net.ranides.assira.text.StringTraits;
|
|
|
-import net.ranides.assira.text.StringUtils;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -42,9 +40,9 @@ import net.ranides.assira.text.StringUtils;
|
|
|
*/
|
|
|
public class CHttpHandler implements URIHandler {
|
|
|
|
|
|
- private static final CHttpHandler THAT = new CHttpHandler();
|
|
|
+ static final CHttpHandler THAT = new CHttpHandler();
|
|
|
|
|
|
- private static final Pattern RE_CHARSET = Pattern.compile(";[ ]+charset=([^; ]+)");
|
|
|
+ private static final Pattern RE_CHARSET = Pattern.compile(";[ ]*charset=([^; ]+)");
|
|
|
|
|
|
private static final String HTTP_NS = "HTTP: unsupported";
|
|
|
|
|
|
@@ -85,7 +83,7 @@ public class CHttpHandler implements URIHandler {
|
|
|
try {
|
|
|
HttpURLConnection c = connect(ustream, "HEAD");
|
|
|
re.add(URIFlags.READABLE);
|
|
|
- if(2 == (c.getResponseCode() % 100)) {
|
|
|
+ if(2 == (c.getResponseCode() / 100)) {
|
|
|
re.add(URIFlags.EXISTS);
|
|
|
}
|
|
|
if(StringTraits.starts(c.getContentType(), "text/")) {
|
|
|
@@ -93,6 +91,9 @@ public class CHttpHandler implements URIHandler {
|
|
|
} else {
|
|
|
re.add(URIFlags.BINARY);
|
|
|
}
|
|
|
+ if(c.getContentLengthLong() >= 0) {
|
|
|
+ re.add(URIFlags.SIZE);
|
|
|
+ }
|
|
|
} catch(IOException cause) {
|
|
|
// do nothing
|
|
|
}
|
|
|
@@ -126,6 +127,12 @@ public class CHttpHandler implements URIHandler {
|
|
|
public InputStream istream(URIHandle ustream) throws IOException {
|
|
|
return ((CHttpHandle)ustream).url.openStream();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public InputStream istream(URIHandle ustream, long offset, long size) throws IOException {
|
|
|
+ // @todo (assira #1) CFileHandler: istream(offset)
|
|
|
+ throw new UnsupportedOperationException("Not supported yet.");
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public OutputStream ostream(URIHandle ustream) throws IOException {
|