|
|
@@ -31,111 +31,129 @@ import net.ranides.assira.text.Charsets;
|
|
|
*
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
|
*/
|
|
|
-public abstract class CHandler implements URIHandler {
|
|
|
+public abstract class CHandle implements URIHandle {
|
|
|
|
|
|
private static final String NSE = "Not supported by URIHandler: ";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String scheme() throws IOException {
|
|
|
+ return uri().getScheme();
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public URI uri(URIHandle ustream) throws IOException {
|
|
|
+ public URI uri() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public File file(URIHandle ustream) throws IOException {
|
|
|
+ public File file() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Path path(URIHandle ustream) throws IOException {
|
|
|
+ public Path path() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Charset charset(URIHandle ustream) throws IOException {
|
|
|
+ public Charset charset() throws IOException {
|
|
|
return Charsets.UTF8;
|
|
|
}
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
- public Set<URIFlags> flags(URIHandle ustream) throws IOException {
|
|
|
+ public Set<URIFlags> flags() throws IOException {
|
|
|
return URIFlags.collect();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Instant time(URIHandle ustream, URITime ut) throws IOException {
|
|
|
+ public boolean exists() throws IOException {
|
|
|
+ return URIFlags.EXISTS.matches(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Instant time(URITime ut) throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public long size(URIHandle ustream) throws IOException {
|
|
|
+ public long size() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public URIHandle parent(URIHandle ustream) throws IOException {
|
|
|
+ public URIHandle parent() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CQuery<URIHandle> scan(URIHandle ustream) throws IOException {
|
|
|
+ public CQuery<URIHandle> scan() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public InputStream istream(URIHandle ustream) throws IOException {
|
|
|
+ public InputStream istream() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public InputStream istream(URIHandle ustream, long begin, long end) throws IOException {
|
|
|
- return IOStreams.limit(istream(ustream), begin, end);
|
|
|
+ public InputStream istream(long begin, long end) throws IOException {
|
|
|
+ return IOStreams.limit(istream(), begin, end);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public OutputStream ostream(URIHandle ustream) throws IOException {
|
|
|
+ public OutputStream ostream() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Reader reader(URIHandle ustream, Charset cs) throws IOException {
|
|
|
- return new InputStreamReader(istream(ustream), cs);
|
|
|
+ public Reader reader(Charset cs) throws IOException {
|
|
|
+ return new InputStreamReader(istream(), cs);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Reader reader(URIHandle ustream) throws IOException {
|
|
|
- return new InputStreamReader(istream(ustream), charset(ustream));
|
|
|
+ public Reader reader() throws IOException {
|
|
|
+ return new InputStreamReader(istream(), charset());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Writer writer(URIHandle ustream, Charset cs) throws IOException {
|
|
|
- return new OutputStreamWriter(ostream(ustream), cs);
|
|
|
+ public Writer writer(Charset cs) throws IOException {
|
|
|
+ return new OutputStreamWriter(ostream(), cs);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Writer writer(URIHandle ustream) throws IOException {
|
|
|
- return new OutputStreamWriter(ostream(ustream), charset(ustream));
|
|
|
+ public Writer writer() throws IOException {
|
|
|
+ return new OutputStreamWriter(ostream(), charset());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void delete(URIHandle ustream) throws IOException {
|
|
|
+ public void delete() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void create(URIHandle ustream) throws IOException {
|
|
|
+ public void create() throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void move(URIHandle ustream, URIHandle location) throws IOException {
|
|
|
+ public void move(String target) throws IOException {
|
|
|
+ move(resolver().resolve(target));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void move(URIHandle target) throws IOException {
|
|
|
throw new IOException(NSE + scheme());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void copy(URIHandle ustream, URIHandle location) throws IOException {
|
|
|
- try(InputStream istream = ustream.istream()) {
|
|
|
- try(OutputStream ostream = location.ostream()) {
|
|
|
+ public void copy(String target) throws IOException {
|
|
|
+ copy(resolver().resolve(target));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void copy(URIHandle target) throws IOException {
|
|
|
+ try(InputStream istream = istream()) {
|
|
|
+ try(OutputStream ostream = target.ostream()) {
|
|
|
IOStreams.copy(istream, ostream);
|
|
|
}
|
|
|
}
|