/[classpath]/inetlib/source/gnu/inet/util/BASE64.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/util/BASE64.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by dog, Thu Oct 21 15:21:55 2004 UTC revision 1.8 by dog, Thu Nov 25 22:15:05 2004 UTC
# Line 1  Line 1 
1  /*  /*
2   * $Id$   * BASE64.java
3   * Copyright (C) 2003 The Free Software Foundation   * Copyright (C) 2003 The Free Software Foundation
4   *   *
5   * This file is part of GNU inetlib, a library.   * This file is part of GNU inetlib, a library.
# Line 42  package gnu.inet.util; Line 42  package gnu.inet.util;
42   * Encodes and decodes text according to the BASE64 encoding.   * Encodes and decodes text according to the BASE64 encoding.
43   *   *
44   * @author <a href="mailto:dog@gnu.org">Chris Burdess</a>   * @author <a href="mailto:dog@gnu.org">Chris Burdess</a>
  * @version $Revision$ $Date$  
45   */   */
46  public final class BASE64  public final class BASE64
47  {  {
# Line 71  public final class BASE64 Line 70  public final class BASE64
70        }        }
71    }    }
72    
73    private BASE64 ()    private BASE64()
74    {    {
75    }    }
76    
# Line 80  public final class BASE64 Line 79  public final class BASE64
79     *     *
80     * @param bs the source byte array     * @param bs the source byte array
81     */     */
82    public static byte[] encode (byte[] bs)    public static byte[] encode(byte[] bs)
83    {    {
84      int si = 0, ti = 0;         // source/target array indices      int si = 0, ti = 0;         // source/target array indices
85      byte[] bt = new byte[((bs.length + 2) * 4) / 3];     // target byte array      byte[] bt = new byte[((bs.length + 2) * 4) / 3];     // target byte array
# Line 155  public final class BASE64 Line 154  public final class BASE64
154          len = srclen - si;          len = srclen - si;
155        }        }
156      byte[] bt = new byte[buflen];      byte[] bt = new byte[buflen];
157      System.arraycopy (buffer, 0, bt, 0, buflen);      System.arraycopy(buffer, 0, bt, 0, buflen);
158      return bt;      return bt;
159    }    }
160        
161    public static void main (String[] args)    public static void main(String[] args)
162    {    {
163      boolean decode = false;      boolean decode = false;
164      for (int i = 0; i < args.length; i++)      for (int i = 0; i < args.length; i++)
165        {        {
166          if (args[i].equals ("-d"))          if (args[i].equals("-d"))
167            {            {
168              decode = true;              decode = true;
169            }            }
# Line 172  public final class BASE64 Line 171  public final class BASE64
171            {            {
172              try              try
173                {                {
174                  byte[] in = args[i].getBytes ("US-ASCII");                  byte[] in = args[i].getBytes("US-ASCII");
175                  byte[] out = decode ? decode (in) : encode (in);                  byte[] out = decode ? decode(in) : encode(in);
176                  System.out.println (args[i] + " = " +                  System.out.println(args[i] + " = " +
177                                      new String (out, "US-ASCII"));                                     new String(out, "US-ASCII"));
178                }                }
179              catch (java.io.UnsupportedEncodingException e)              catch (java.io.UnsupportedEncodingException e)
180                {                {
181                  e.printStackTrace (System.err);                  e.printStackTrace(System.err);
182                }                }
183            }            }
184        }        }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26