## net.i2p.data
Class Base64

    java.lang.Object
      net.i2p.data.Base64

    public class Base64

extends Object

Encodes and decodes to and from Base64 notation.

Change Log:

- v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.
- v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream where last buffer being read, if not completely full, was not returned.
- v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.
- v1.3.3 - Fixed I/O streams which were totally messed up.

I am placing this code in the Public Domain. Do with it as you will. This software comes with no guarantees or warranties but with plenty of well-wishing instead! Please visit http://iharder.net/xmlizable periodically to check for updates or to contribute improvements.

Modified by jrandom for i2p, using safeEncode / safeDecode to create filesystem and URL safe base64 values (replacing / with ~, and + with -)

Version:
  1.3.4
Author:
  Robert Harder, rob@iharder.net

Method Summary
`static byte[]` `decode(String s)` Decodes data from Base64 notation.
`static String` `decodeToString(String s)` Decodes data from Base64 notation and returns it as a string.
`static String` `encode(byte[] source)`
`static String` `encode(byte[] source, boolean useStandardAlphabet)`
`static String` `encode(byte[] source, int off, int len)`
`static String` `encode(byte[] source, int off, int len, boolean useStandardAlphabet)`
`static String` `encode(String source)`
`static void` `main(String[] args)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### encode

    public static String encode(String source)

  Parameters:
    `source` - if null will return ""

### encode

    public static String encode(byte[] source)

  Parameters:
    `source` - if null will return ""

### encode

    public static String encode(byte[] source,
                                int off,
                                int len)

  Parameters:
    `source` - if null will return ""

### encode

    public static String encode(byte[] source,
                                boolean useStandardAlphabet)

  Parameters:
    `source` - if null will return ""
    `useStandardAlphabet` - Warning, must be false for I2P compatibility

### encode

    public static String encode(byte[] source,
                                int off,
                                int len,
                                boolean useStandardAlphabet)

  Parameters:
    `source` - if null will return ""
    `useStandardAlphabet` - Warning, must be false for I2P compatibility

### decode

    public static byte[] decode(String s)

  Decodes data from Base64 notation.

  Parameters:
    `s` - Base 64 encoded string using the I2P alphabet A-Z, a-z, 0-9, -, ~
  Returns:
    the decoded data, null on error

### main

    public static void main(String[] args)

### decodeToString

    public static String decodeToString(String s)

  Decodes data from Base64 notation and returns it as a string. Equivlaent to calling `new String( decode( s ) )`

  Parameters:
    `s` - the strind to decode
  Returns:
    The data as a string
  Throws:
    `NPE` - on error?
  Since:
    1.4