Ranides Atterwim 4 年之前
父節點
當前提交
f001b52c17
共有 1 個文件被更改,包括 15 次插入18 次删除
  1. 15 18
      assira.core/src/main/java/net/ranides/assira/io/uri/impl/CDataHandler.java

+ 15 - 18
assira.core/src/main/java/net/ranides/assira/io/uri/impl/CDataHandler.java

@@ -99,13 +99,11 @@ public class CDataHandler implements URIHandler {
      */
     private class CDataHandle extends CHandle {
 
-        public final URI uri;
-        public final String mime;
-        public final boolean isText;
-        public final boolean isBase64;
-        public final Charset charset;
-        public final byte[] data;
-        public final String text;
+        private final URI uri;
+        private final MaskSet<URIFlags> flags;
+        private final Charset charset;
+        private final byte[] data;
+        private final String text;
 
         public CDataHandle(URI uri) throws IOException {
             Matcher hit = RE_DATA_SCHEME.matcher(uri.getRawSchemeSpecificPart());
@@ -113,20 +111,19 @@ public class CDataHandler implements URIHandler {
                 throw new IOException("Invalid data URI: " + uri);
             }
 
+            boolean isBase64 = hit.group(3) != null;
+            String mime = ValueUtils.or(hit.group(1), "text/plain");
+
             this.uri = uri;
-            this.mime = ValueUtils.or(hit.group(1), "text/plain");
             this.charset = getCharset(hit.group(2));
-            this.isText = mime.startsWith("text/");
-            this.isBase64 = hit.group(3) != null;
-
-            String body = hit.group(4);
+            this.flags = mime.startsWith("text/") ? TXT_FLAGS : BIN_FLAGS;
 
-            if(!isBase64) {
-                text = URLDecoder.decode(body, charset.name());
-                data = text.getBytes(charset);
-            } else {
-                data = Base64.getDecoder().decode(body);
+            if (isBase64) {
+                data = Base64.getDecoder().decode(hit.group(4));
                 text = new String(data, charset);
+            } else {
+                text = URLDecoder.decode(hit.group(4), charset.name());
+                data = text.getBytes(charset);
             }
         }
 
@@ -166,7 +163,7 @@ public class CDataHandler implements URIHandler {
         
         @Override
         public Set<URIFlags> flags() {
-            return isText ? TXT_FLAGS : BIN_FLAGS;
+            return flags;
         }
 
         @Override