/*
 *  The OpenDiamond Platform for Interactive Search
 *  Version 5
 *
 *  Copyright (c) 2009 Carnegie Mellon University
 *  All rights reserved.
 *
 *  This software is distributed under the terms of the Eclipse Public
 *  License, Version 1.0 which can be found in the file named LICENSE.
 *  ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS SOFTWARE CONSTITUTES
 *  RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT
 */

package edu.cmu.cs.diamond.opendiamond;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

class XDR_attr_name_list implements XDREncodeable {

    private final String strings[];

    public XDR_attr_name_list(Collection<String> list) {
        strings = list.toArray(new String[0]);
    }

    public byte[] encode() {
        // length + strings

        int finalSize = 4;
        List<byte[]> bufs = new ArrayList<byte[]>();
        for (String s : strings) {
            byte[] bb = XDREncoders.encodeString(s);
            bufs.add(bb);
            finalSize += bb.length;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(baos);

        try {
            // length
            out.writeInt(strings.length);

            // strings
            for (byte b[] : bufs) {
                out.write(b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return baos.toByteArray();
    }

}

@@ -890,249 +890,8 @@
 gs%0A%0A
-        int finalSize = 4;%0A        List%3Cbyte%5B%5D%3E bufs = new ArrayList%3Cbyte%5B%5D%3E();%0A        for (String s : strings) %7B%0A            byte%5B%5D bb = XDREncoders.encodeString(s);%0A            bufs.add(bb);%0A            finalSize += bb.length;%0A        %7D%0A%0A
     
@@ -948,24 +948,24 @@
 utStream();%0A
+
         Data
@@ -1135,22 +1135,25 @@
 or (
-byte b%5B%5D : buf
+String s : string
 s) %7B
@@ -1179,17 +1179,43 @@
 t.write(
-b
+XDREncoders.encodeString(s)
 );%0A     

Clean up XDR_attr_name_list.encode()