Ranides Atterwim 10 سال پیش
والد
کامیت
491f20d80e

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

@@ -70,7 +70,7 @@ public class CHttpHandler extends CHandler {
         Set<URIFlags> re = URIFlags.collect(URIFlags.FILE);
         try {
             HttpURLConnection c = connect(ustream, "HEAD");
-            if(2 == (c.getResponseCode() / 100)) {
+            if(isSuccess(c)) {
                 re.add(URIFlags.EXISTS);
                 re.add(URIFlags.READABLE);
             }
@@ -131,7 +131,7 @@ public class CHttpHandler extends CHandler {
 
     @Override
     public OutputStream ostream(URIHandle ustream) throws IOException {
-        HttpURLConnection c = connect(ustream, "PUT");
+        HttpURLConnection c = connect(ustream, "POST");
         c.connect();
         return c.getOutputStream();
     }
@@ -152,24 +152,44 @@ public class CHttpHandler extends CHandler {
 
     @Override
     public Writer writer(URIHandle ustream, Charset cs) throws IOException {
-        HttpURLConnection c = connect(ustream, "PUT");
+        HttpURLConnection c = connect(ustream, "POST");
         c.connect();
         return new OutputStreamWriter(c.getOutputStream(), cs);
     }
     
     @Override
     public Writer writer(URIHandle ustream) throws IOException {
-        HttpURLConnection c = connect(ustream, "PUT");
+        HttpURLConnection c = connect(ustream, "POST");
         c.connect();
         return new OutputStreamWriter(c.getOutputStream(), getContentCharset(c.getContentType()));
     }
 
+    @Override
+    public void create(URIHandle ustream) throws IOException {
+        HttpURLConnection c = connect(ustream, "PUT");
+        if(!isSuccess(c)) {
+            throw new IOException(c.getResponseCode() + ": " + c.getResponseMessage());
+        }
+    }
+
+    @Override
+    public void delete(URIHandle ustream) throws IOException {
+        HttpURLConnection c = connect(ustream, "DELETE");
+        if(!isSuccess(c)) {
+            throw new IOException(c.getResponseCode() + ": " + c.getResponseMessage());
+        }
+    }
+    
     private HttpURLConnection connect(URIHandle ustream, String method) throws IOException {
         HttpURLConnection c = (HttpURLConnection)((CHttpHandle)ustream).uri.toURL().openConnection();
         c.setRequestMethod(method);
         return c;
     }
     
+    private static boolean isSuccess(HttpURLConnection c) throws IOException {
+        return 2 == (c.getResponseCode() / 100);
+    }
+    
     private static Charset getContentCharset(String type) throws IOException {
         if(null == type) {
             throw new IOException("Unknown MIME type");

+ 9 - 0
assira/src/test/java/net/ranides/assira/io/uri/impl/CHttpHandlerTest.java

@@ -142,4 +142,13 @@ public class CHttpHandlerTest {
         assertEquals("61b37c0973bc00bd33606a2f5050e64baec3a7df",IOStrings.read(file, Charsets.UTF8));
     }
     
+    @Test
+    public void testMove() throws IOException, URISyntaxException {
+        URIHandle src = CHttpHandler.THAT.resolve(new URI("http://maven.ranides.net/net/ranides/assira/0.58/assira-0.58.jar.sha1"));
+        URIHandle dst = CHttpHandler.THAT.resolve(new URI("http://maven.ranides.net/net/ranides/assira/0.58/assira-0.58.jar.sha1m"));
+        assertThrows(IOException.class, ()->{
+            src.move(dst);
+        });
+    }
+    
 }