Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * File:  xml_utils.java.java
 *
 * Copyright (C) 2002,  Ruth Mikkelson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contact : Ruth Mikkelson <mikkelsonr@uwstout.edu>
 *           Department of Mathematics, Statistics and Computer Science
 *           University of Wisconsin-Stout
 *           Menomonie, WI 54751, USA
 *
 * This work was supported by the Intense Pulsed Neutron Source Division
 * of Argonne National Laboratory, Argonne, IL 60439-4845, USA.
 *
 * For further information, see <http://www.pns.anl.gov/ISAW/>
 *
 * Modified:
 *
 *  $Log$
 *  Revision 1.10  2004/03/11 23:07:13  dennis
 *  Removed dependency on DataSet Attributes
 *
 *  Revision 1.9  2004/01/22 02:19:05  bouzekc
 *  Removed unused imports and local variables.
 *
 *  Revision 1.8  2003/10/20 16:31:06  rmikk
 *  Fixed javadoc errors
 *
 *  Revision 1.7  2003/06/18 20:35:35  pfpeterson
 *  Changed calls for NxNodeUtils.Showw(Object) to
 *  DataSetTools.util.StringUtil.toString(Object)
 *
 *  Revision 1.6  2003/03/03 16:49:16  pfpeterson
 *  Changed SharedData.status_pane.add(String) to SharedData.addmsg(String)
 *
 *  Revision 1.5  2002/11/27 23:14:07  pfpeterson
 *  standardized header
 *
 *  Revision 1.4  2002/11/12 03:36:24  dennis
 *  Since Attributes are no longer mutable, this can't call setValue()
 *  for Double, Float and Int Attributes (line 421).  This must still be
 *  modified to adapt to immutable Attributes.
 *
 *  Revision 1.3  2002/07/10 19:35:23  rmikk
 *  Change in documentation
 *
 *  Revision 1.2  2002/06/17 22:46:19  rmikk
 *  Prettied  up the file. Made minor changes
 *
 *  Revision 1.1  2002/06/14 21:25:44  rmikk
 *  Common utilities for Implementers of the IXmlIO interface
 *
 */

import java.io.*;

public class Main {
    private static final int fillchar = '=';
    private static final String cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

            // 22223333333333444444444455
            // 67890123456789012345678901
            + "abcdefghijklmnopqrstuvwxyz"

            // 555555556666
            // 234567890123
            + "0123456789+/";

    public static int[] convertB64Toint(byte[] a1) {
        byte[] a = decode(a1);
        try {
            ByteArrayInputStream is = new ByteArrayInputStream(a1);
            DataInputStream di = new DataInputStream(is);
            int[] f = new int[a.length / 4];
            for (int i = 0; i < f.length; i++)
                f[i] = di.readInt();
            return f;
        } catch (Exception s) {
            return null;
        }

    }

    public static byte[] decode(byte[] data) {
        int c;
        int c1;
        int len = data.length;
        StringBuffer ret = new StringBuffer((len * 3) / 4);
        for (int i = 0; i < len; ++i) {
            c = cvt.indexOf(data[i]);
            ++i;
            c1 = cvt.indexOf(data[i]);
            c = ((c << 2) | ((c1 >> 4) & 0x3));
            ret.append((char) c);
            if (++i < len) {
                c = data[i];
                if (fillchar == c)
                    break;

                c = cvt.indexOf((char) c);
                c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
                ret.append((char) c1);
            }

            if (++i < len) {
                c1 = data[i];
                if (fillchar == c1)
                    break;

                c1 = cvt.indexOf((char) c1);
                c = ((c << 6) & 0xc0) | c1;
                ret.append((char) c);
            }
        }

        return (getBinaryBytes(ret.toString()));
    }

    private static byte[] getBinaryBytes(String str) {
        byte[] b = new byte[str.length()];
        for (int i = 0; i < b.length; ++i)
            b[i] = (byte) str.charAt(i);

        return (b);
    }
}