Просмотр исходного кода

resolve #86: URIHandle#content and #text

Ranides Atterwim 3 лет назад
Родитель
Сommit
6ceceea0e6

+ 5 - 6
assira.commons/src/test/java/net/ranides/assira/io/uri/impl/CDataHandlerTest.java

@@ -4,7 +4,6 @@ import org.junit.Test;
 
 import net.ranides.assira.io.IOStreams;
 import net.ranides.assira.io.uri.URIHandle;
-import net.ranides.assira.io.uri.impl.CDataHandler;
 import net.ranides.assira.text.FormatHex;
 
 import java.io.IOException;
@@ -24,11 +23,11 @@ public class CDataHandlerTest {
         URIHandle handle5 = new CDataHandler().resolve("data:text/plain;charset=iso-8859-7,%be%20%f0%20%ee");
 
 
-        assertEquals("the data:1234,5678", handle1.content());
-        assertEquals("hello world", handle2.content());
-        assertEquals("źrebię na łące skacze po łące", handle3.content());
-        assertEquals("źrebię na łące skacze po łące", handle4.content());
-        assertEquals("Ύ π ξ", handle5.content());
+        assertEquals("the data:1234,5678", handle1.text());
+        assertEquals("hello world", handle2.text());
+        assertEquals("źrebię na łące skacze po łące", handle3.text());
+        assertEquals("źrebię na łące skacze po łące", handle4.text());
+        assertEquals("Ύ π ξ", handle5.text());
     }
 
     @Test

+ 7 - 7
assira.core/src/main/java/net/ranides/assira/io/uri/URIHandle.java

@@ -17,11 +17,10 @@ import java.net.URI;
 import java.nio.charset.Charset;
 import java.nio.file.Path;
 import java.time.Instant;
-import java.util.Map;
 import java.util.Set;
 import net.ranides.assira.collection.query.CQuery;
+import net.ranides.assira.io.IOStreams;
 import net.ranides.assira.text.IOStrings;
-import net.ranides.assira.text.StringUtils;
 
 /**
  * This is abstraction over URL, File and Path objects.
@@ -163,9 +162,6 @@ public interface URIHandle extends Closeable {
      */
     Instant time(URITime ut) throws IOException;
 
-    // @todo #86
-    // Map<URITime, Instant> time() throws IOException;
-
     /**
      * Returns size of this resource, in bytes.
      *
@@ -307,7 +303,7 @@ public interface URIHandle extends Closeable {
      * @return string
      * @throws IOException on error
      */
-    default String content() throws IOException {
+    default String text() throws IOException {
         return IOStrings.read(reader());
     }
 
@@ -322,10 +318,14 @@ public interface URIHandle extends Closeable {
      * @return string
      * @throws IOException on error
      */
-    default String content(Charset cs) throws IOException {
+    default String text(Charset cs) throws IOException {
         return IOStrings.read(reader(cs));
     }
 
+    default byte[] content() throws IOException {
+        return IOStreams.read(istream());
+    }
+
     /**
      * Filesystem I/O operation: removes this resource.
      *