Selaa lähdekoodia

ZOOKEEPER-3391: Drop unused RecFormat(CSV/XML)

As described in

http://zookeeper-user.578899.n2.nabble.com/Deprecated-CSVInputArchive-and-XMLInputArchive-td7584086.html

these 2 input archives(CSV/XML) are not actively maintained and we probably don't have test coverage for them either, so keeping them in the codebase could be questionable.

Without input archives, output archives are also meaningless. Thus transitive removals of `CSVOutputArchive` and `XMLOutputArchive`.

One problem is we also use `CSVOutputArchive` for record `toString` method. For backward compatibility, I rename it to `ToStringOutputArchive` and remain almost all methods. We might discuss another `toString` gen path but it should work as now.

Author: tison <wander4096@gmail.com>

Reviewers: eolivelli@apache.org, andor@apache.org

Closes #983 from TisonKun/ZOOKEEPER-3391
tison 5 vuotta sitten
vanhempi
commit
92257ef143

+ 0 - 204
zookeeper-jute/src/main/java/org/apache/jute/CsvInputArchive.java

@@ -1,204 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jute;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PushbackReader;
-import java.io.UnsupportedEncodingException;
-
-/**
- *
- */
-class CsvInputArchive implements InputArchive {
-    
-    private PushbackReader stream;
-    
-    private class CsvIndex implements Index {
-        public boolean done() {
-            char c = '\0';
-            try {
-                c = (char) stream.read();
-                stream.unread(c);
-            } catch (IOException ex) {
-            }
-            return (c == '}') ? true : false;
-        }
-        public void incr() {}
-    }
-    
-    private String readField(String tag) throws IOException {
-        try {
-            StringBuilder buf = new StringBuilder();
-            while (true) {
-                char c = (char) stream.read();
-                switch (c) {
-                    case ',':
-                        return buf.toString();
-                    case '}':
-                    case '\n':
-                    case '\r':
-                        stream.unread(c);
-                        return buf.toString();
-                    default:
-                        buf.append(c);
-                }
-            }
-        } catch (IOException ex) {
-            throw new IOException("Error reading "+tag);
-        }
-    }
-    
-    static CsvInputArchive getArchive(InputStream strm)
-    throws UnsupportedEncodingException {
-        return new CsvInputArchive(strm);
-    }
-    
-    /** Creates a new instance of CsvInputArchive */
-    public CsvInputArchive(InputStream in)
-    throws UnsupportedEncodingException {
-        stream = new PushbackReader(new InputStreamReader(in, "UTF-8"));
-    }
-    
-    public byte readByte(String tag) throws IOException {
-        return (byte) readLong(tag);
-    }
-    
-    public boolean readBool(String tag) throws IOException {
-        String sval = readField(tag);
-        return "T".equals(sval) ? true : false;
-    }
-    
-    public int readInt(String tag) throws IOException {
-        return (int) readLong(tag);
-    }
-    
-    public long readLong(String tag) throws IOException {
-        String sval = readField(tag);
-        try {
-            long lval = Long.parseLong(sval);
-            return lval;
-        } catch (NumberFormatException ex) {
-            throw new IOException("Error deserializing "+tag);
-        }
-    }
-    
-    public float readFloat(String tag) throws IOException {
-        return (float) readDouble(tag);
-    }
-    
-    public double readDouble(String tag) throws IOException {
-        String sval = readField(tag);
-        try {
-            double dval = Double.parseDouble(sval);
-            return dval;
-        } catch (NumberFormatException ex) {
-            throw new IOException("Error deserializing "+tag);
-        }
-    }
-    
-    public String readString(String tag) throws IOException {
-        String sval = readField(tag);
-        return Utils.fromCSVString(sval);
-        
-    }
-    
-    public byte[] readBuffer(String tag) throws IOException {
-        String sval = readField(tag);
-        return Utils.fromCSVBuffer(sval);
-    }
-    
-    public void readRecord(Record r, String tag) throws IOException {
-        r.deserialize(this, tag);
-    }
-    
-    public void startRecord(String tag) throws IOException {
-        if (tag != null && !"".equals(tag)) {
-            char c1 = (char) stream.read();
-            char c2 = (char) stream.read();
-            if (c1 != 's' || c2 != '{') {
-                throw new IOException("Error deserializing "+tag);
-            }
-        }
-    }
-    
-    public void endRecord(String tag) throws IOException {
-        char c = (char) stream.read();
-        if (tag == null || "".equals(tag)) {
-            if (c != '\n' && c != '\r') {
-                throw new IOException("Error deserializing record.");
-            } else {
-                return;
-            }
-        }
-        
-        if (c != '}') {
-            throw new IOException("Error deserializing "+tag);
-        }
-        c = (char) stream.read();
-        if (c != ',') {
-            stream.unread(c);
-        }
-        
-        return;
-    }
-    
-    public Index startVector(String tag) throws IOException {
-        char c1 = (char) stream.read();
-        char c2 = (char) stream.read();
-        if (c1 != 'v' || c2 != '{') {
-            throw new IOException("Error deserializing "+tag);
-        }
-        return new CsvIndex();
-    }
-    
-    public void endVector(String tag) throws IOException {
-        char c = (char) stream.read();
-        if (c != '}') {
-            throw new IOException("Error deserializing "+tag);
-        }
-        c = (char) stream.read();
-        if (c != ',') {
-            stream.unread(c);
-        }
-        return;
-    }
-    
-    public Index startMap(String tag) throws IOException {
-        char c1 = (char) stream.read();
-        char c2 = (char) stream.read();
-        if (c1 != 'm' || c2 != '{') {
-            throw new IOException("Error deserializing "+tag);
-        }
-        return new CsvIndex();
-    }
-    
-    public void endMap(String tag) throws IOException {
-        char c = (char) stream.read();
-        if (c != '}') {
-            throw new IOException("Error deserializing "+tag);
-        }
-        c = (char) stream.read();
-        if (c != ',') {
-            stream.unread(c);
-        }
-        return;
-    }
-}

+ 0 - 6
zookeeper-jute/src/main/java/org/apache/jute/RecordReader.java

@@ -42,12 +42,6 @@ public class RecordReader {
             archiveFactory.put("binary",
                     BinaryInputArchive.class.getDeclaredMethod(
                         "getArchive", new Class[]{ InputStream.class } ));
-            archiveFactory.put("csv",
-                    CsvInputArchive.class.getDeclaredMethod(
-                        "getArchive", new Class[]{ InputStream.class }));
-            archiveFactory.put("xml",
-                    XmlInputArchive.class.getDeclaredMethod(
-                        "getArchive", new Class[]{ InputStream.class }));
         } catch (SecurityException ex) {
             ex.printStackTrace();
         } catch (NoSuchMethodException ex) {

+ 0 - 6
zookeeper-jute/src/main/java/org/apache/jute/RecordWriter.java

@@ -39,12 +39,6 @@ public class RecordWriter {
             factory.put("binary",
                     BinaryOutputArchive.class.getDeclaredMethod(
                         "getArchive", new Class[]{ OutputStream.class }));
-            factory.put("csv",
-                    CsvOutputArchive.class.getDeclaredMethod(
-                        "getArchive", new Class[]{ OutputStream.class }));
-            factory.put("xml",
-                    XmlOutputArchive.class.getDeclaredMethod(
-                        "getArchive", new Class[]{ OutputStream.class }));
         } catch (SecurityException ex) {
             ex.printStackTrace();
         } catch (NoSuchMethodException ex) {

+ 59 - 12
zookeeper-jute/src/main/java/org/apache/jute/CsvOutputArchive.java → zookeeper-jute/src/main/java/org/apache/jute/ToStringOutputArchive.java

@@ -28,16 +28,11 @@ import java.util.TreeMap;
 /**
  *
  */
-public class CsvOutputArchive implements OutputArchive {
+public class ToStringOutputArchive implements OutputArchive {
 
     private PrintStream stream;
     private boolean isFirst = true;
-    
-    static CsvOutputArchive getArchive(OutputStream strm)
-    throws UnsupportedEncodingException {
-        return new CsvOutputArchive(strm);
-    }
-    
+
     private void throwExceptionOnError(String tag) throws IOException {
         if (stream.checkError()) {
             throw new IOException("Error serializing "+tag);
@@ -51,8 +46,8 @@ public class CsvOutputArchive implements OutputArchive {
         isFirst = false;
     }
     
-    /** Creates a new instance of CsvOutputArchive */
-    public CsvOutputArchive(OutputStream out)
+    /** Creates a new instance of ToStringOutputArchive */
+    public ToStringOutputArchive(OutputStream out)
     throws UnsupportedEncodingException {
         stream = new PrintStream(out, true, "UTF-8");
     }
@@ -90,14 +85,14 @@ public class CsvOutputArchive implements OutputArchive {
     
     public void writeString(String s, String tag) throws IOException {
         printCommaUnlessFirst();
-        stream.print(Utils.toCSVString(s));
+        stream.print(escapeString(s));
         throwExceptionOnError(tag);
     }
     
-    public void writeBuffer(byte buf[], String tag)
+    public void writeBuffer(byte[] buf, String tag)
     throws IOException {
         printCommaUnlessFirst();
-        stream.print(Utils.toCSVBuffer(buf));
+        stream.print(escapeBuffer(buf));
         throwExceptionOnError(tag);
     }
     
@@ -147,4 +142,56 @@ public class CsvOutputArchive implements OutputArchive {
         stream.print("}");
         isFirst = false;
     }
+
+    private static String escapeString(String s) {
+        if (s == null) {
+            return "";
+        }
+
+        StringBuilder sb = new StringBuilder(s.length() + 1);
+        sb.append('\'');
+        int len = s.length();
+        for (int i = 0; i < len; i++) {
+            char c = s.charAt(i);
+            switch(c) {
+                case '\0':
+                    sb.append("%00");
+                    break;
+                case '\n':
+                    sb.append("%0A");
+                    break;
+                case '\r':
+                    sb.append("%0D");
+                    break;
+                case ',':
+                    sb.append("%2C");
+                    break;
+                case '}':
+                    sb.append("%7D");
+                    break;
+                case '%':
+                    sb.append("%25");
+                    break;
+                default:
+                    sb.append(c);
+            }
+        }
+
+        return sb.toString();
+    }
+
+    private static String escapeBuffer(byte[] barr) {
+        if (barr == null || barr.length == 0) {
+            return "";
+        }
+
+        StringBuilder sb = new StringBuilder(barr.length + 1);
+        sb.append('#');
+
+        for (byte b : barr) {
+            sb.append(Integer.toHexString(b));
+        }
+
+        return sb.toString();
+    }
 }

+ 0 - 218
zookeeper-jute/src/main/java/org/apache/jute/Utils.java

@@ -18,9 +18,6 @@
 
 package org.apache.jute;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
 /**
  * Various utility functions for Hadoop record I/O runtime.
  */
@@ -51,222 +48,7 @@ public class Utils {
         }
         return true;
     }
-    
-    private static final char[] hexchars = { '0', '1', '2', '3', '4', '5',
-                                            '6', '7', '8', '9', 'A', 'B',
-                                            'C', 'D', 'E', 'F' };
-    /**
-     * 
-     * @param s 
-     * @return 
-     */
-    static String toXMLString(String s) {
-        if (s == null)
-            return "";
 
-        StringBuilder sb = new StringBuilder();
-        for (int idx = 0; idx < s.length(); idx++) {
-          char ch = s.charAt(idx);
-          if (ch == '<') {
-            sb.append("&lt;");
-          } else if (ch == '&') {
-            sb.append("&amp;");
-          } else if (ch == '%') {
-            sb.append("%25");
-          } else if (ch < 0x20) {
-            sb.append("%");
-            sb.append(hexchars[ch/16]);
-            sb.append(hexchars[ch%16]);
-          } else {
-            sb.append(ch);
-          }
-        }
-        return sb.toString();
-    }
-    
-    static private int h2c(char ch) {
-      if (ch >= '0' && ch <= '9') {
-        return ch - '0';
-      } else if (ch >= 'A' && ch <= 'F') {
-        return ch - 'A';
-      } else if (ch >= 'a' && ch <= 'f') {
-        return ch - 'a';
-      }
-      return 0;
-    }
-    
-    /**
-     * 
-     * @param s 
-     * @return 
-     */
-    static String fromXMLString(String s) {
-        StringBuilder sb = new StringBuilder();
-        for (int idx = 0; idx < s.length();) {
-          char ch = s.charAt(idx++);
-          if (ch == '%') {
-            char ch1 = s.charAt(idx++);
-            char ch2 = s.charAt(idx++);
-            char res = (char)(h2c(ch1)*16 + h2c(ch2));
-            sb.append(res);
-          } else {
-            sb.append(ch);
-          }
-        }
-        
-        return sb.toString();
-    }
-    
-    /**
-     * 
-     * @param s 
-     * @return 
-     */
-    static String toCSVString(String s) {
-        if (s == null)
-            return "";
-
-        StringBuilder sb = new StringBuilder(s.length()+1);
-        sb.append('\'');
-        int len = s.length();
-        for (int i = 0; i < len; i++) {
-            char c = s.charAt(i);
-            switch(c) {
-                case '\0':
-                    sb.append("%00");
-                    break;
-                case '\n':
-                    sb.append("%0A");
-                    break;
-                case '\r':
-                    sb.append("%0D");
-                    break;
-                case ',':
-                    sb.append("%2C");
-                    break;
-                case '}':
-                    sb.append("%7D");
-                    break;
-                case '%':
-                    sb.append("%25");
-                    break;
-                default:
-                    sb.append(c);
-            }
-        }
-        return sb.toString();
-    }
-    
-    /**
-     * 
-     * @param s 
-     * @throws java.io.IOException 
-     * @return 
-     */
-    static String fromCSVString(String s) throws IOException {
-        if (s.charAt(0) != '\'') {
-            throw new IOException("Error deserializing string.");
-        }
-        int len = s.length();
-        StringBuilder sb = new StringBuilder(len-1);
-        for (int i = 1; i < len; i++) {
-            char c = s.charAt(i);
-            if (c == '%') {
-                char ch1 = s.charAt(i+1);
-                char ch2 = s.charAt(i+2);
-                i += 2;
-                if (ch1 == '0' && ch2 == '0') { sb.append('\0'); }
-                else if (ch1 == '0' && ch2 == 'A') { sb.append('\n'); }
-                else if (ch1 == '0' && ch2 == 'D') { sb.append('\r'); }
-                else if (ch1 == '2' && ch2 == 'C') { sb.append(','); }
-                else if (ch1 == '7' && ch2 == 'D') { sb.append('}'); }
-                else if (ch1 == '2' && ch2 == '5') { sb.append('%'); }
-                else {throw new IOException("Error deserializing string.");}
-            } else {
-                sb.append(c);
-            }
-        }
-        return sb.toString();
-    }
-    
-    /**
-     * 
-     * @param s 
-     * @return 
-     */
-    static String toXMLBuffer(byte barr[]) {
-        if (barr == null || barr.length == 0) {
-            return "";
-        }
-        StringBuilder sb = new StringBuilder(2*barr.length);
-        for (int idx = 0; idx < barr.length; idx++) {
-            sb.append(Integer.toHexString(barr[idx]));
-        }
-        return sb.toString();
-    }
-    
-    /**
-     * 
-     * @param s 
-     * @throws java.io.IOException 
-     * @return 
-     */
-    static byte[] fromXMLBuffer(String s)
-    throws IOException {
-        ByteArrayOutputStream stream =  new ByteArrayOutputStream();
-        if (s.length() == 0) { return stream.toByteArray(); }
-        int blen = s.length()/2;
-        byte[] barr = new byte[blen];
-        for (int idx = 0; idx < blen; idx++) {
-            char c1 = s.charAt(2*idx);
-            char c2 = s.charAt(2*idx+1);
-            barr[idx] = Byte.parseByte(""+c1+c2, 16);
-        }
-        stream.write(barr);
-        return stream.toByteArray();
-    }
-    
-    /**
-     * 
-     * @param buf 
-     * @return 
-     */
-    static String toCSVBuffer(byte barr[]) {
-        if (barr == null || barr.length == 0) {
-            return "";
-        }
-        StringBuilder sb = new StringBuilder(barr.length + 1);
-        sb.append('#');
-        for(int idx = 0; idx < barr.length; idx++) {
-            sb.append(Integer.toHexString(barr[idx]));
-        }
-        return sb.toString();
-    }
-    
-    /**
-     * Converts a CSV-serialized representation of buffer to a new
-     * ByteArrayOutputStream.
-     * @param s CSV-serialized representation of buffer
-     * @throws java.io.IOException 
-     * @return Deserialized ByteArrayOutputStream
-     */
-    static byte[] fromCSVBuffer(String s)
-    throws IOException {
-        if (s.charAt(0) != '#') {
-            throw new IOException("Error deserializing buffer.");
-        }
-        ByteArrayOutputStream stream =  new ByteArrayOutputStream();
-        if (s.length() == 1) { return stream.toByteArray(); }
-        int blen = (s.length()-1)/2;
-        byte[] barr = new byte[blen];
-        for (int idx = 0; idx < blen; idx++) {
-            char c1 = s.charAt(2*idx+1);
-            char c2 = s.charAt(2*idx+2);
-            barr[idx] = Byte.parseByte(""+c1+c2, 16);
-        }
-        stream.write(barr);
-        return stream.toByteArray();
-    }
     public static int compareBytes(byte b1[], int off1, int len1, byte b2[], int off2, int len2) {
         int i;
         for(i=0; i < len1 && i < len2; i++) {

+ 0 - 253
zookeeper-jute/src/main/java/org/apache/jute/XmlInputArchive.java

@@ -1,253 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jute;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-/**
- *
- */
-class XmlInputArchive implements InputArchive {
-    
-    static private class Value {
-        private String type;
-        private StringBuffer sb;
-        
-        public Value(String t) {
-            type = t;
-            sb = new StringBuffer();
-        }
-        public void addChars(char[] buf, int offset, int len) {
-            sb.append(buf, offset, len);
-        }
-        public String getValue() { return sb.toString(); }
-        public String getType() { return type; }
-    }
-    
-    private static class XMLParser extends DefaultHandler {
-        private boolean charsValid = false;
-        
-        private ArrayList<Value> valList;
-        
-        private XMLParser(ArrayList<Value> vlist) {
-            valList = vlist;
-        }
-        
-        public void startDocument() throws SAXException {}
-        
-        public void endDocument() throws SAXException {}
-        
-        public void startElement(String ns,
-                String sname,
-                String qname,
-                Attributes attrs) throws SAXException {
-            charsValid = false;
-            if ("boolean".equals(qname) ||
-                    "i4".equals(qname) ||
-                    "int".equals(qname) ||
-                    "string".equals(qname) ||
-                    "double".equals(qname) ||
-                    "ex:i1".equals(qname) ||
-                    "ex:i8".equals(qname) ||
-                    "ex:float".equals(qname)) {
-                charsValid = true;
-                valList.add(new Value(qname));
-            } else if ("struct".equals(qname) ||
-                "array".equals(qname)) {
-                valList.add(new Value(qname));
-            }
-        }
-        
-        public void endElement(String ns,
-                String sname,
-                String qname) throws SAXException {
-            charsValid = false;
-            if ("struct".equals(qname) ||
-                    "array".equals(qname)) {
-                valList.add(new Value("/"+qname));
-            }
-        }
-        
-        public void characters(char buf[], int offset, int len)
-        throws SAXException {
-            if (charsValid) {
-                Value v = valList.get(valList.size()-1);
-                v.addChars(buf, offset,len);
-            }
-        }
-        
-    }
-    
-    private class XmlIndex implements Index {
-        public boolean done() {
-            Value v = valList.get(vIdx);
-            if ("/array".equals(v.getType())) {
-                valList.set(vIdx, null);
-                vIdx++;
-                return true;
-            } else {
-                return false;
-            }
-        }
-        public void incr() {}
-    }
-    
-    private ArrayList<Value> valList;
-    private int vLen;
-    private int vIdx;
-    
-    private Value next() throws IOException {
-        if (vIdx < vLen) {
-            Value v = valList.get(vIdx);
-            valList.set(vIdx, null);
-            vIdx++;
-            return v;
-        } else {
-            throw new IOException("Error in deserialization.");
-        }
-    }
-    
-    static XmlInputArchive getArchive(InputStream strm)
-    throws ParserConfigurationException, SAXException, IOException {
-        return new XmlInputArchive(strm);
-    }
-    
-    /** Creates a new instance of BinaryInputArchive */
-    public XmlInputArchive(InputStream in)
-    throws ParserConfigurationException, SAXException, IOException {
-        valList = new ArrayList<Value>();
-        DefaultHandler handler = new XMLParser(valList);
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
-        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-        SAXParser parser = factory.newSAXParser();
-        parser.parse(in, handler);
-        vLen = valList.size();
-        vIdx = 0;
-    }
-    
-    public byte readByte(String tag) throws IOException {
-        Value v = next();
-        if (!"ex:i1".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Byte.parseByte(v.getValue());
-    }
-    
-    public boolean readBool(String tag) throws IOException {
-        Value v = next();
-        if (!"boolean".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return "1".equals(v.getValue());
-    }
-    
-    public int readInt(String tag) throws IOException {
-        Value v = next();
-        if (!"i4".equals(v.getType()) &&
-                !"int".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Integer.parseInt(v.getValue());
-    }
-    
-    public long readLong(String tag) throws IOException {
-        Value v = next();
-        if (!"ex:i8".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Long.parseLong(v.getValue());
-    }
-    
-    public float readFloat(String tag) throws IOException {
-        Value v = next();
-        if (!"ex:float".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Float.parseFloat(v.getValue());
-    }
-    
-    public double readDouble(String tag) throws IOException {
-        Value v = next();
-        if (!"double".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Double.parseDouble(v.getValue());
-    }
-    
-    public String readString(String tag) throws IOException {
-        Value v = next();
-        if (!"string".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Utils.fromXMLString(v.getValue());
-    }
-    
-    public byte[] readBuffer(String tag) throws IOException {
-        Value v = next();
-        if (!"string".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return Utils.fromXMLBuffer(v.getValue());
-    }
-    
-    public void readRecord(Record r, String tag) throws IOException {
-        r.deserialize(this, tag);
-    }
-    
-    public void startRecord(String tag) throws IOException {
-        Value v = next();
-        if (!"struct".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-    }
-    
-    public void endRecord(String tag) throws IOException {
-        Value v = next();
-        if (!"/struct".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-    }
-    
-    public Index startVector(String tag) throws IOException {
-        Value v = next();
-        if (!"array".equals(v.getType())) {
-            throw new IOException("Error deserializing "+tag+".");
-        }
-        return new XmlIndex();
-    }
-    
-    public void endVector(String tag) throws IOException {}
-    
-    public Index startMap(String tag) throws IOException {
-        return startVector(tag);
-    }
-    
-    public void endMap(String tag) throws IOException { endVector(tag); }
-
-}

+ 0 - 251
zookeeper-jute/src/main/java/org/apache/jute/XmlOutputArchive.java

@@ -1,251 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jute;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.List;
-import java.util.Stack;
-import java.util.TreeMap;
-
-/**
- *
- */
-class XmlOutputArchive implements OutputArchive {
-
-    private PrintStream stream;
-    
-    private int indent = 0;
-    
-    private Stack<String> compoundStack;
-    
-    private void putIndent() {
-        StringBuilder sb = new StringBuilder("");
-        for (int idx = 0; idx < indent; idx++) {
-            sb.append("  ");
-        }
-        stream.print(sb.toString());
-    }
-    
-    private void addIndent() {
-        indent++;
-    }
-    
-    private void closeIndent() {
-        indent--;
-    }
-    
-    private void printBeginEnvelope(String tag) {
-        if (!compoundStack.empty()) {
-            String s = compoundStack.peek();
-            if ("struct".equals(s)) {
-                putIndent();
-                stream.print("<member>\n");
-                addIndent();
-                putIndent();
-                stream.print("<name>"+tag+"</name>\n");
-                putIndent();
-                stream.print("<value>");
-            } else if ("vector".equals(s)) {
-                stream.print("<value>");
-            } else if ("map".equals(s)) {
-                stream.print("<value>");
-            }
-        } else {
-            stream.print("<value>");
-        }
-    }
-    
-    private void printEndEnvelope(String tag) {
-        if (!compoundStack.empty()) {
-            String s = compoundStack.peek();
-            if ("struct".equals(s)) {
-                stream.print("</value>\n");
-                closeIndent();
-                putIndent();
-                stream.print("</member>\n");
-            } else if ("vector".equals(s)) {
-                stream.print("</value>\n");
-            } else if ("map".equals(s)) {
-                stream.print("</value>\n");
-            }
-        } else {
-            stream.print("</value>\n");
-        }
-    }
-    
-    private void insideVector(String tag) {
-        printBeginEnvelope(tag);
-        compoundStack.push("vector");
-    }
-    
-    private void outsideVector(String tag) throws IOException {
-        String s = compoundStack.pop();
-        if (!"vector".equals(s)) {
-            throw new IOException("Error serializing vector.");
-        }
-        printEndEnvelope(tag);
-    }
-    
-    private void insideMap(String tag) {
-        printBeginEnvelope(tag);
-        compoundStack.push("map");
-    }
-    
-    private void outsideMap(String tag) throws IOException {
-        String s = compoundStack.pop();
-        if (!"map".equals(s)) {
-            throw new IOException("Error serializing map.");
-        }
-        printEndEnvelope(tag);
-    }
-    
-    private void insideRecord(String tag) {
-        printBeginEnvelope(tag);
-        compoundStack.push("struct");
-    }
-    
-    private void outsideRecord(String tag) throws IOException {
-        String s = compoundStack.pop();
-        if (!"struct".equals(s)) {
-            throw new IOException("Error serializing record.");
-        }
-        printEndEnvelope(tag);
-    }
-    
-    static XmlOutputArchive getArchive(OutputStream strm) {
-        return new XmlOutputArchive(strm);
-    }
-    
-    /** Creates a new instance of XmlOutputArchive */
-    public XmlOutputArchive(OutputStream out) {
-        stream = new PrintStream(out);
-        compoundStack = new Stack<String>();
-    }
-    
-    public void writeByte(byte b, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<ex:i1>");
-        stream.print(Byte.toString(b));
-        stream.print("</ex:i1>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeBool(boolean b, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<boolean>");
-        stream.print(b ? "1" : "0");
-        stream.print("</boolean>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeInt(int i, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<i4>");
-        stream.print(Integer.toString(i));
-        stream.print("</i4>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeLong(long l, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<ex:i8>");
-        stream.print(Long.toString(l));
-        stream.print("</ex:i8>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeFloat(float f, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<ex:float>");
-        stream.print(Float.toString(f));
-        stream.print("</ex:float>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeDouble(double d, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<double>");
-        stream.print(Double.toString(d));
-        stream.print("</double>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeString(String s, String tag) throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<string>");
-        stream.print(Utils.toXMLString(s));
-        stream.print("</string>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeBuffer(byte buf[], String tag)
-    throws IOException {
-        printBeginEnvelope(tag);
-        stream.print("<string>");
-        stream.print(Utils.toXMLBuffer(buf));
-        stream.print("</string>");
-        printEndEnvelope(tag);
-    }
-    
-    public void writeRecord(Record r, String tag) throws IOException {
-        r.serialize(this, tag);
-    }
-    
-    public void startRecord(Record r, String tag) throws IOException {
-        insideRecord(tag);
-        stream.print("<struct>\n");
-        addIndent();
-    }
-    
-    public void endRecord(Record r, String tag) throws IOException {
-        closeIndent();
-        putIndent();
-        stream.print("</struct>");
-        outsideRecord(tag);
-    }
-    
-    public void startVector(List<?> v, String tag) throws IOException {
-        insideVector(tag);
-        stream.print("<array>\n");
-        addIndent();
-    }
-    
-    public void endVector(List<?> v, String tag) throws IOException {
-        closeIndent();
-        putIndent();
-        stream.print("</array>");
-        outsideVector(tag);
-    }
-    
-    public void startMap(TreeMap<?,?> v, String tag) throws IOException {
-        insideMap(tag);
-        stream.print("<array>\n");
-        addIndent();
-    }
-    
-    public void endMap(TreeMap<?,?> v, String tag) throws IOException {
-        closeIndent();
-        putIndent();
-        stream.print("</array>");
-        outsideMap(tag);
-    }
-
-}

+ 2 - 2
zookeeper-jute/src/main/java/org/apache/jute/compiler/JRecord.java

@@ -481,8 +481,8 @@ public class JRecord extends JCompType {
             jj.write("    try {\n");
             jj.write("      java.io.ByteArrayOutputStream s =\n");
             jj.write("        new java.io.ByteArrayOutputStream();\n");
-            jj.write("      CsvOutputArchive a_ = \n");
-            jj.write("        new CsvOutputArchive(s);\n");
+            jj.write("      ToStringOutputArchive a_ = \n");
+            jj.write("        new ToStringOutputArchive(s);\n");
             jj.write("      a_.startRecord(this,\"\");\n");
             fIdx = 0;
             for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {

+ 2 - 138
zookeeper-jute/src/main/java/org/apache/jute/package.html

@@ -285,7 +285,7 @@ Declarations of these interfaces and a description of their semantics follow:
 <pre><code>
 namespace hadoop {
 
-  enum RecFormat { kBinary, kXML, kCSV };
+  enum RecFormat { kBinary };
 
   class InStream {
   public:
@@ -621,7 +621,7 @@ map<type,type>  std::map<type,type> java.util.TreeMap
 <h2>Data encodings</h2>
 
 This section describes the format of the data encodings supported by Hadoop.
-Currently, three data encodings are supported, namely binary, CSV and XML.
+Currently, one data encoding is supported, namely binary.
 
 <h3>Binary Serialization Format</h3>
 
@@ -661,141 +661,5 @@ language representation.
 raw bytes in the buffer.
 </ul>
 
-
-<h3>CSV Serialization Format</h3>
-
-The CSV serialization format has a lot more structure than the "standard"
-Excel CSV format, but we believe the additional structure is useful because
-
-<ul>
-<li> it makes parsing a lot easier without detracting too much from legibility
-<li> the delimiters around composites make it obvious when one is reading a
-sequence of Hadoop records
-</ul>
-
-Serialization formats for the various types are detailed in the grammar that
-follows. The notable feature of the formats is the use of delimiters for 
-indicating the certain field types.
-
-<ul>
-<li> A string field begins with a single quote (').
-<li> A buffer field begins with a sharp (#).
-<li> A class, vector or map begins with 's{', 'v{' or 'm{' respectively and
-ends with '}'.
-</ul>
-
-The CSV format can be described by the following grammar:
-
-<pre><code>
-record = primitive / struct / vector / map
-primitive = boolean / int / long / float / double / ustring / buffer
-
-boolean = "T" / "F"
-int = ["-"] 1*DIGIT
-long = ";" ["-"] 1*DIGIT
-float = ["-"] 1*DIGIT "." 1*DIGIT ["E" / "e" ["-"] 1*DIGIT]
-double = ";" ["-"] 1*DIGIT "." 1*DIGIT ["E" / "e" ["-"] 1*DIGIT]
-
-ustring = "'" *(UTF8 char except NULL, LF, % and , / "%00" / "%0a" / "%25" / "%2c" )
-
-buffer = "#" *(BYTE except NULL, LF, % and , / "%00" / "%0a" / "%25" / "%2c" )
-
-struct = "s{" record *("," record) "}"
-vector = "v{" [record *("," record)] "}"
-map = "m{" [*(record "," record)] "}"
-</code></pre>
-
-<h3>XML Serialization Format</h3>
-
-The XML serialization format is the same used by Apache XML-RPC
-(http://ws.apache.org/xmlrpc/types.html). This is an extension of the original
-XML-RPC format and adds some additional data types. All record I/O types are
-not directly expressible in this format, and access to a DDL is required in
-order to convert these to valid types. All types primitive or composite are
-represented by &lt;value&gt; elements. The particular XML-RPC type is
-indicated by a nested element in the &lt;value&gt; element. The encoding for
-records is always UTF-8. Primitive types are serialized as follows:
-
-<ul>
-<li> byte: XML tag &lt;ex:i1&gt;. Values: 1-byte unsigned 
-integers represented in US-ASCII
-<li> boolean: XML tag &lt;boolean&gt;. Values: "0" or "1"
-<li> int: XML tags &lt;i4&gt; or &lt;int&gt;. Values: 4-byte
-signed integers represented in US-ASCII.
-<li> long: XML tag &lt;ex:i8&gt;. Values: 8-byte signed integers
-represented in US-ASCII.
-<li> float: XML tag &lt;ex:float&gt;. Values: Single precision
-floating point numbers represented in US-ASCII.
-<li> double: XML tag &lt;double&gt;. Values: Double precision
-floating point numbers represented in US-ASCII.
-<li> ustring: XML tag &lt;;string&gt;. Values: String values
-represented as UTF-8. XML does not permit all Unicode characters in literal
-data. In particular, NULLs and control chars are not allowed. Additionally,
-XML processors are required to replace carriage returns with line feeds and to
-replace CRLF sequences with line feeds. Programming languages that we work
-with do not impose these restrictions on string types. To work around these
-restrictions, disallowed characters and CRs are percent escaped in strings.
-The '%' character is also percent escaped.
-<li> buffer: XML tag &lt;string&&gt;. Values: Arbitrary binary
-data. Represented as hexBinary, each byte is replaced by its 2-byte
-hexadecimal representation.
-</ul>
-
-Composite types are serialized as follows:
-
-<ul>
-<li> class: XML tag &lt;struct&gt;. A struct is a sequence of
-&lt;member&gt; elements. Each &lt;member&gt; element has a &lt;name&gt;
-element and a &lt;value&gt; element. The &lt;name&gt; is a string that must
-match /[a-zA-Z][a-zA-Z0-9_]*/. The value of the member is represented
-by a &lt;value&gt; element.
-
-<li> vector: XML tag &lt;array&lt;. An &lt;array&gt; contains a
-single &lt;data&gt; element. The &lt;data&gt; element is a sequence of
-&lt;value&gt; elements each of which represents an element of the vector.
-
-<li> map: XML tag &lt;array&gt;. Same as vector.
-
-</ul>
-
-For example:
-
-<pre><code>
-class {
-  int           MY_INT;            // value 5
-  vector<float> MY_VEC;            // values 0.1, -0.89, 2.45e4
-  buffer        MY_BUF;            // value '\00\n\tabc%'
-}
-</code></pre>
-
-is serialized as
-
-<pre><code class="XML">
-&lt;value&gt;
-  &lt;struct&gt;
-    &lt;member&gt;
-      &lt;name&gt;MY_INT&lt;/name&gt;
-      &lt;value&gt;&lt;i4&gt;5&lt;/i4&gt;&lt;/value&gt;
-    &lt;/member&gt;
-    &lt;member&gt;
-      &lt;name&gt;MY_VEC&lt;/name&gt;
-      &lt;value&gt;
-        &lt;array&gt;
-          &lt;data&gt;
-            &lt;value&gt;&lt;ex:float&gt;0.1&lt;/ex:float&gt;&lt;/value&gt;
-            &lt;value&gt;&lt;ex:float&gt;-0.89&lt;/ex:float&gt;&lt;/value&gt;
-            &lt;value&gt;&lt;ex:float&gt;2.45e4&lt;/ex:float&gt;&lt;/value&gt;
-          &lt;/data&gt;
-        &lt;/array&gt;
-      &lt;/value&gt;
-    &lt;/member&gt;
-    &lt;member&gt;
-      &lt;name&gt;MY_BUF&lt;/name&gt;
-      &lt;value&gt;&lt;string&gt;%00\n\tabc%25&lt;/string&gt;&lt;/value&gt;
-    &lt;/member&gt;
-  &lt;/struct&gt;
-&lt;/value&gt; 
-</code></pre>
-
   </body>
 </html>

+ 0 - 96
zookeeper-jute/src/test/java/org/apache/jute/UtilsTest.java

@@ -1,96 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jute;
-
-import org.junit.Assert;
-import org.junit.Test;
-import java.io.IOException;
-
-
-public class UtilsTest {
-
-    void assertXMLString(String input) {
-        String xmlString = Utils.toXMLString(input);
-        String actual = Utils.fromXMLString(xmlString);
-        Assert.assertEquals(input, actual);
-    }
-
-    @Test
-    public void testXMLString() {
-        assertXMLString("hello");
-        assertXMLString(",}%"); // special characters
-    }
-
-    void assertXMLBuffer(byte[] input) {
-        String xmlString = Utils.toXMLBuffer(input);
-        try {
-            byte[] actual = Utils.fromXMLBuffer(xmlString);
-            Assert.assertArrayEquals (input, actual);
-        } catch (IOException ioex) {
-            Assert.fail("Should not be throwing an IOException");
-        }
-    }
-
-    @Test
-    public void testXMLBuffer() {
-        assertXMLBuffer("hello".getBytes());
-    }
-
-
-    void assertCSVString(String input) {
-        String csvString = Utils.toCSVString(input);
-        try {
-            String actual = Utils.fromCSVString(csvString);
-            Assert.assertEquals(input, actual);
-        } catch (IOException ioex) {
-            Assert.fail("Should not be throwing an IOException");
-        }
-    }
-
-    @Test
-    public void testCSVString() {
-        assertCSVString("hello");
-        assertCSVString(",}%");        // special characters
-    }
-
-    @Test
-    public void testFromCSVString() {
-        try {
-            Utils.fromCSVString("1"); // not starting with '
-            Assert.fail("Should have thrown an IOException");
-        } catch (IOException ioex) {
-
-        }
-    }
-
-    void assertCSVBuffer(byte[] input) {
-        String csvBuffer = Utils.toCSVBuffer(input);
-        try {
-            byte[] actual = Utils.fromCSVBuffer(csvBuffer);
-            Assert.assertArrayEquals(input, actual);
-        } catch (IOException ioex) {
-            Assert.fail("Should not have thrown IOException during assertCSVBuffer");
-        }
-    }
-
-    @Test
-    public void testCSVBuffer() {
-        assertCSVBuffer("universe".getBytes());
-    }
-
-}

+ 0 - 127
zookeeper-jute/src/test/java/org/apache/jute/XmlInputArchiveTest.java

@@ -1,127 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jute;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertArrayEquals;
-
-import org.junit.Test;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.ParserConfigurationException;
-import java.nio.charset.StandardCharsets;
-import java.io.IOException;
-
-public class XmlInputArchiveTest {
-
-    private void checkWriterAndReader(TestWriter writer, TestReader reader) {
-        TestCheckWriterReader.checkWriterAndReader(
-                XmlOutputArchive::getArchive,
-                (is) -> {
-                    try {
-                        return XmlInputArchive.getArchive(is);
-                    } catch (ParserConfigurationException|SAXException e) {
-                        throw new IOException(e);
-                    }
-                },
-                writer,
-                reader
-        );
-    }
-
-    @Test
-    public void testWriteInt() {
-        final int expected = 4;
-        final String tag = "tag1";
-        checkWriterAndReader(
-                (oa) -> oa.writeInt(expected, tag),
-                (ia) -> {
-                    int actual = ia.readInt(tag);
-                    assertEquals(expected, actual);
-                }
-        );
-    }
-
-    @Test
-    public void testWriteBool() {
-        final boolean expected = false;
-        final String tag = "tag1";
-        checkWriterAndReader(
-                (oa) -> oa.writeBool(expected, tag),
-                (ia) -> {
-                    boolean actual = ia.readBool(tag);
-                    assertEquals(expected, actual);
-                }
-        );
-    }
-
-    @Test
-    public void testWriteString() {
-        final String expected = "hello";
-        final String tag = "tag1";
-        checkWriterAndReader(
-                (oa) -> oa.writeString(expected, tag),
-                (ia) -> {
-                    String actual = ia.readString(tag);
-                    assertEquals(expected, actual);
-                }
-        );
-    }
-
-    @Test
-    public void testWriteFloat() {
-        final float expected = 3.14159f;
-        final String tag = "tag1";
-        final float delta = 1e-10f;
-        checkWriterAndReader(
-                (oa) -> oa.writeFloat(expected, tag),
-                (ia) -> {
-                    float actual = ia.readFloat(tag);
-                    assertEquals(expected, actual, delta);
-                }
-        );
-    }
-
-    @Test
-    public void testWriteDouble() {
-        final double expected = 3.14159f;
-        final String tag = "tag1";
-        final float delta = 1e-20f;
-        checkWriterAndReader(
-                (oa) -> oa.writeDouble(expected, tag),
-                (ia) -> {
-                    double actual = ia.readDouble(tag);
-                    assertEquals(expected, actual, delta);
-                }
-        );
-    }
-
-    @Test
-    public void testBuffer() {
-        final byte[] expected = "hello-world".getBytes(StandardCharsets.UTF_8);
-        final String tag = "tag1";
-        checkWriterAndReader(
-                (oa) -> oa.writeBuffer(expected, tag),
-                (ia) -> {
-                    byte [] actual = ia.readBuffer(tag);
-                    assertArrayEquals(expected, actual);
-                }
-        );
-    }
-
-}