// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:43:28
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/app/StreamDataSource

package com.macromedia.generator.app;

import java.io.*;
import java.util.Vector;

// Referenced classes of package com.macromedia.generator.app:
//            FlashEnvironment

public class StreamDataSource
{

    public StreamDataSource()
    {
        _fld0106 = true;
        _fld0107 = 34;
        _fld0108 = 44;
    }

    public String[][] getData(InputStream inputstream, String s)
    {
        String as[][] = null;
        String s1 = env.getDataEncoding();
        try
        {
            Vector vector = new Vector();
            BufferedReader bufferedreader;
            if(s1 != null)
                bufferedreader = new BufferedReader(new InputStreamReader(inputstream, s1));
            else
                bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
            StreamTokenizer streamtokenizer = new StreamTokenizer(bufferedreader);
            streamtokenizer.resetSyntax();
            streamtokenizer.whitespaceChars(13, 13);
            streamtokenizer.whitespaceChars(10, 10);
            streamtokenizer.eolIsSignificant(true);
            if(_fld0106)
                streamtokenizer.quoteChar(_fld0107);
            String as1[] = _mth0106(streamtokenizer, 0);
            if(as1 != null)
            {
                vector.addElement(as1);
                int i = as1.length;
                for(String as2[] = _mth0106(streamtokenizer, i); as2 != null; as2 = _mth0106(streamtokenizer, i))
                    vector.addElement(as2);

            }
            if(!vector.isEmpty())
            {
                int j = vector.size();
                as = new String[j][];
                for(int k = 0; k < j; k++)
                    as[k] = (String[])vector.elementAt(k);

            }
        }
        catch(UnsupportedEncodingException _ex)
        {
            env.logError("com.macromedia.generator.resources.DataSourceData", "UnsupportedEncoding", s1);
            as = null;
        }
        catch(Exception _ex)
        {
            env.logError("com.macromedia.generator.resources.DataSourceData", "IOException", s);
            as = null;
        }
        return as;
    }

    private String[] _mth0106(StreamTokenizer streamtokenizer, int i)
        throws IOException
    {
        String as[] = null;
        StringBuffer stringbuffer = new StringBuffer(80);
        Vector vector = new Vector();
        for(int j = streamtokenizer.nextToken(); vector.isEmpty() && j != -1;)
        {
            while(j != 10 && j != -1) 
            {
                int k = 0;
                stringbuffer.setLength(0);
                for(; j != 10 && j != -1 && j != _fld0108; j = streamtokenizer.nextToken())
                    if(_fld0106 && j == _fld0107)
                    {
                        k = 0;
                        stringbuffer.setLength(0);
                        stringbuffer.append(streamtokenizer.sval);
                    } else
                    if(j == -3)
                        stringbuffer.append(streamtokenizer.sval);
                    else
                    if(j > 32 || stringbuffer.length() > 0)
                    {
                        if(j > 32)
                            k = 0;
                        else
                            k++;
                        stringbuffer.append((char)j);
                    }

                if(k > 0)
                    stringbuffer.setLength(stringbuffer.length() - k);
                if(j == _fld0108 || stringbuffer.length() > 0)
                    vector.addElement(stringbuffer.toString());
                if(j == _fld0108)
                    j = streamtokenizer.nextToken();
            }
            if(vector.isEmpty() && j == 10)
                j = streamtokenizer.nextToken();
        }

        int l = vector.size();
        if(l > 0)
        {
            if(i > l)
            {
                for(int i1 = l; i1 < i; i1++)
                    vector.addElement(new String(""));

                l = i;
            }
            if(i > 0)
                l = i;
            if(l > 0)
            {
                as = new String[l];
                for(int j1 = 0; j1 < l; j1++)
                    as[j1] = (String)vector.elementAt(j1);

            }
        }
        return as;
    }

    public void setCommaDelimiter()
    {
        _fld0108 = 44;
    }

    public void setCustomDelimiter(char c)
    {
        _fld0108 = c;
    }

    public void setDoubleQuotes()
    {
        _fld0106 = true;
        _fld0107 = 34;
    }

    public void setEnvironment(FlashEnvironment flashenvironment)
    {
        env = flashenvironment;
    }

    public void setNoQuotes()
    {
        _fld0106 = false;
    }

    public void setSemicolonDelimiter()
    {
        _fld0108 = 59;
    }

    public void setSingleQuotes()
    {
        _fld0106 = true;
        _fld0107 = 39;
    }

    public void setTabDelimiter()
    {
        _fld0108 = 9;
    }

    protected FlashEnvironment env;
    private boolean _fld0106;
    private int _fld0107;
    private int _fld0108;
}