Ranides Atterwim 10 سال پیش
والد
کامیت
46f36edfe3

+ 8 - 0
assira/src/main/java/net/ranides/assira/io/uri/URIHandle.java

@@ -99,10 +99,18 @@ public abstract class URIHandle {
         return system.reader(this);
     }
     
+    public Reader reader(Charset cs) throws IOException {
+        return system.reader(this, cs);
+    }
+    
     public Writer writer() throws IOException {
         return system.writer(this);
     }
     
+    public Writer writer(Charset cs) throws IOException {
+        return system.writer(this, cs);
+    }
+    
     public void delete() throws IOException {
         system.delete(this);
     }

+ 9 - 2
assira/src/main/java/net/ranides/assira/io/uri/URIHandler.java

@@ -58,10 +58,17 @@ public interface URIHandler {
     
     OutputStream ostream(URIHandle ustream) throws IOException;
     
-    Reader reader(URIHandle ustream) throws IOException;
+    default Reader reader(URIHandle ustream) throws IOException {
+        return reader(ustream, ustream.charset());
+    }
+    
+    Reader reader(URIHandle ustream, Charset cs) throws IOException;
     
-    Writer writer(URIHandle ustream) throws IOException;
+    default Writer writer(URIHandle ustream) throws IOException {
+        return writer(ustream, ustream.charset());
+    }
     
+    Writer writer(URIHandle ustream, Charset cs) throws IOException;
     
     
     void delete(URIHandle ustream) throws IOException;

+ 1 - 0
assira/src/main/java/net/ranides/assira/io/uri/URIResolver.java

@@ -10,6 +10,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 import java.util.Map;
 import java.util.ServiceLoader;
 import net.ranides.assira.collection.maps.HashMap;

+ 4 - 4
assira/src/main/java/net/ranides/assira/io/uri/impl/CFileHandler.java

@@ -150,13 +150,13 @@ public class CFileHandler implements URIHandler {
     }
 
     @Override
-    public Reader reader(URIHandle ustream) throws IOException {
-        return new InputStreamReader(ustream.istream(), ustream.charset());
+    public Reader reader(URIHandle ustream, Charset cs) throws IOException {
+        return new InputStreamReader(ustream.istream(), cs);
     }
 
     @Override
-    public Writer writer(URIHandle ustream) throws IOException {
-        return new OutputStreamWriter(ustream.ostream(),ustream.charset());
+    public Writer writer(URIHandle ustream, Charset cs) throws IOException {
+        return new OutputStreamWriter(ustream.ostream(), cs);
     }
 
     @Override

+ 16 - 0
assira/src/main/java/net/ranides/assira/io/uri/impl/CHttpHandler.java

@@ -155,6 +155,14 @@ public class CHttpHandler  implements URIHandler {
         c.connect();
         return c.getOutputStream();
     }
+    
+    @Override
+    public Reader reader(URIHandle ustream, Charset cs) throws IOException {
+        HttpURLConnection c = connect(ustream);
+        c.setRequestMethod("GET");
+        c.connect();
+        return new InputStreamReader(c.getInputStream(), cs);
+    }
 
     @Override
     public Reader reader(URIHandle ustream) throws IOException {
@@ -164,6 +172,14 @@ public class CHttpHandler  implements URIHandler {
         return new InputStreamReader(c.getInputStream(), getContentCharset(c.getContentType()));
     }
 
+    @Override
+    public Writer writer(URIHandle ustream, Charset cs) throws IOException {
+        HttpURLConnection c = connect(ustream);
+        c.setRequestMethod("PUT");
+        c.connect();
+        return new OutputStreamWriter(c.getOutputStream(), cs);
+    }
+    
     @Override
     public Writer writer(URIHandle ustream) throws IOException {
         HttpURLConnection c = connect(ustream);