Returns the length of the decoded base64 input (written to the
provided {@code output} byte array).
The {@code output} byte array must have enough capacity or it will fail.
559908
public static int decodeTo(final byte[] output, int outOffset, 
            final String str, int inOffset, final int inLen)
    {
        if(inLen == 0)
            return 0;
        
        if (inLen%4!=0)
            throw new IllegalArgumentException("Input block size is not 4");

        int withoutPaddingLen = inLen, limit = inOffset + inLen;
        while (str.charAt(--limit)==pad)
            withoutPaddingLen--;

        // Create result array of exact required size.
        final int outLen=((withoutPaddingLen)*3)/4;
        //assert (output.length - outOffset) >= outLen;
        
        decode(str, inOffset, inLen, output, outOffset, outLen);

        return outLen;
    }
436666
public static String base64Encode(byte[] bytes) {
    if (bytes == null) {
      throw new IllegalArgumentException("Input bytes must not be null.");
    }
    if (bytes.length >= BASE64_UPPER_BOUND) {
      throw new IllegalArgumentException(
          "Input bytes length must not exceed " + BASE64_UPPER_BOUND);
    }

    // Every three bytes is encoded into four characters.
    //
    // Example:
    //           input |0 1 0 1 0 0 1 0|0 1 1 0 1 1 1 1|0 1 1 0 0 0 1 0|
    // encode grouping |0 1 0 1 0 0|1 0 0 1 1 0|1 1 1 1 0 1|1 0 0 0 1 0|
    //   encoded ascii |     U     |     m     |     9     |     i     |

    int triples = bytes.length / 3;

    // If the number of input bytes is not a multiple of three, padding characters will be added.
    if (bytes.length % 3 != 0) {
      triples += 1;
    }

    // The encoded string will have four characters for every three bytes.
    char[] encoding = new char[triples << 2];

    for (int in = 0, out = 0; in < bytes.length; in += 3, out += 4) {
      int triple = (bytes[in] & 0xff) << 16;
      if (in + 1 < bytes.length) {
        triple |= ((bytes[in + 1] & 0xff) << 8);
      }
      if (in + 2 < bytes.length) {
        triple |= (bytes[in + 2] & 0xff);
      }
      encoding[out] = BASE64_CHARS.charAt((triple >> 18) & 0x3f);
      encoding[out + 1] = BASE64_CHARS.charAt((triple >> 12) & 0x3f);
      encoding[out + 2] = BASE64_CHARS.charAt((triple >> 6) & 0x3f);
      encoding[out + 3] = BASE64_CHARS.charAt(triple & 0x3f);
    }

    // Add padding characters if needed.
    for (int i = encoding.length - (triples * 3 - bytes.length); i < encoding.length; i++) {
      encoding[i] = '=';
    }

    return String.valueOf(encoding);
  }
1108434
public static String encode(byte[] input) {
      if (input.length == 0) {
         return "";
      }
      input = copyOfRange(input, 0, input.length);
      // Count leading zeroes.
      int zeroCount = 0;
      while (zeroCount < input.length && input[zeroCount] == 0) {
         ++zeroCount;
      }
      // The actual encoding.
      byte[] temp = new byte[input.length * 2];
      int j = temp.length;

      int startAt = zeroCount;
      while (startAt < input.length) {
         byte mod = divmod58(input, startAt);
         if (input[startAt] == 0) {
            ++startAt;
         }
         temp[--j] = (byte) ALPHABET[mod];
      }

      // Strip extra '1' if there are some after decoding.
      while (j < temp.length && temp[j] == ALPHABET[0]) {
         ++j;
      }
      // Add as many leading '1' as there were leading zeros.
      while (--zeroCount >= 0) {
         temp[--j] = (byte) ALPHABET[0];
      }

      byte[] output = copyOfRange(temp, j, temp.length);
      try {
         return new String(output, "US-ASCII");
      } catch (UnsupportedEncodingException e) {
         throw new RuntimeException(e); // Cannot happen.
      }
   }
125937
protected int prepareOutput(int length)
        throws IOException
    {   
        if (_out==null)
            throw new IOException("closed");
        checkOutput();
        if (!_written)
        {
            _written=true;
            notify(OutputObserver.__FIRST_WRITE);
        }        
        
        if (_contentLength>=0)
        {
            if (_bytes+length>=_contentLength)
            {
                length=_contentLength-_bytes;
                if (length==0)
                    _nulled=true;
            }
        }
        _bytes+=length;
        return length;
    }
147941
public final byte[] decode(byte[] source, int off, int len) {
		int	len34 = len * 3 / 4;
		byte[] outBuff = new byte[len34]; // upper limit on size of output
		int	outBuffPosn = 0;
		
		byte[] b4 = new byte[4];
		int	b4Posn = 0;
		int	i = 0;
		byte sbiCrop = 0;
		byte sbiDecode = 0;
		for (i = off; i < off + len; i++) {
			sbiCrop = (byte)(source[i] & 0x7f); // only the low seven bits
			sbiDecode = DECODABET[sbiCrop];
			
			if (sbiDecode >= WHITE_SPACE_ENC) { // white space, equals sign or better
				if (sbiDecode >= PADDING_CHAR_ENC) {
					b4[b4Posn++] = sbiCrop;
					if (b4Posn > 3) {
						outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn);
						b4Posn = 0;
						
						// if that was the padding char, break out of 'for' loop
						if (sbiCrop == PADDING_CHAR) {
							break;
						}
					} // end if: quartet built
				} // end if: equals sign or better
			} // end if: white space, equals sign or better
			else {
				//discard
			} 
		} // each input character
								   
		byte[] out = new byte[outBuffPosn];
		System.arraycopy(outBuff, 0, out, 0, outBuffPosn); 
		return out;
	}
1258336
public void writeLength(long length) {
    if (length < 251) {
      buf[position++] = (byte) length;
    } else if (length < 65536) {
      buf[position++] = (byte) 0xfc;
      buf[position++] = (byte) length;
      buf[position++] = (byte) (length >>> 8);
    } else if (length < 16777216) {
      buf[position++] = (byte) 0xfd;
      buf[position++] = (byte) length;
      buf[position++] = (byte) (length >>> 8);
      buf[position++] = (byte) (length >>> 16);
    } else {
      buf[position++] = (byte) 0xfe;
      buf[position++] = (byte) length;
      buf[position++] = (byte) (length >>> 8);
      buf[position++] = (byte) (length >>> 16);
      buf[position++] = (byte) (length >>> 24);
      buf[position++] = (byte) (length >>> 32);
      buf[position++] = (byte) (length >>> 40);
      buf[position++] = (byte) (length >>> 48);
      buf[position++] = (byte) (length >>> 54);
    }
  }
199249
public byte[] getLengthEncodedBytes() {
    int type = this.buf[this.position++] & 0xff;
    int length;
    switch (type) {
      case 251:
        return null;
      case 252:
        length = 0xffff & readShort();
        break;
      case 253:
        length = 0xffffff & read24bitword();
        break;
      case 254:
        length = (int) ((buf[position++] & 0xff)
            + ((long) (buf[position++] & 0xff) << 8)
            + ((long) (buf[position++] & 0xff) << 16)
            + ((long) (buf[position++] & 0xff) << 24)
            + ((long) (buf[position++] & 0xff) << 32)
            + ((long) (buf[position++] & 0xff) << 40)
            + ((long) (buf[position++] & 0xff) << 48)
            + ((long) (buf[position++] & 0xff) << 56));
        break;
      default:
        length = type;
        break;
    }

    byte[] tmpBuf = new byte[length];
    System.arraycopy(buf, position, tmpBuf, 0, length);
    position += length;
    return tmpBuf;
  }
265181
public byte[] getOutput() {
		if (stringWriter != null) {
			byte[] output = null;

			String string = stringWriter.toString();
			if (string != null) {
				try {
					output = string.getBytes(characterEncoding);
				} catch (UnsupportedEncodingException uue) {
					output = null;
				}
			}

			return output;
		} else if (outputStream != null) {
			return outputStream.getOutput();
		}

		return null;
	}
1184436
public String getDecodedOutput() {
        byte[] bytes = com.amazonaws.util.BinaryUtils.fromBase64(output);
        return new String(bytes, com.amazonaws.util.StringUtils.UTF8);
    }
765656
public long readRawLittleEndian64() throws IOException
    {
        final byte b1 = readRawByte();
        final byte b2 = readRawByte();
        final byte b3 = readRawByte();
        final byte b4 = readRawByte();
        final byte b5 = readRawByte();
        final byte b6 = readRawByte();
        final byte b7 = readRawByte();
        final byte b8 = readRawByte();
        return (((long) b1 & 0xff)) |
                (((long) b2 & 0xff) << 8) |
                (((long) b3 & 0xff) << 16) |
                (((long) b4 & 0xff) << 24) |
                (((long) b5 & 0xff) << 32) |
                (((long) b6 & 0xff) << 40) |
                (((long) b7 & 0xff) << 48) |
                (((long) b8 & 0xff) << 56);
    }
1066868
public static byte[] encode(InputStream in) {
        Base64OutputStream out = null;
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            out = new Base64OutputStream(bytes);
            byte[] buf = new byte[4096];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            out.flush();
            return bytes.toByteArray();
        } catch (IOException e) {
            return null;
        } finally {
            try {
                in.close();
                if (out != null) out.close();
            } catch (IOException e) {
                throw new FaultException(e);
            }
        }
    }
197617
protected String getBase64(InputStream in) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		CopyUtil.copy(in, out);
		return new String(Base64.encodeBase64(out.toByteArray()), "UTF-8"); //$NON-NLS-1$
	}
360653
public static String encodeBytes(final byte[] source) {
    return Base64.encodeBytes(source, 0, source.length, Base64.NO_OPTIONS);
  }
165110
public long readRawVarint64() throws IOException
    {
        int shift = 0;
        long result = 0;
        while (shift < 64)
        {
            final byte b = readRawByte();
            result |= (long) (b & 0x7F) << shift;
            if ((b & 0x80) == 0)
            {
                return result;
            }
            shift += 7;
        }
        throw ProtobufException.malformedVarint();
    }
242081
private static long readVLong(DataInput stream) throws IOException {
    byte firstByte = stream.readByte();
    int len = decodeVIntSize(firstByte);
    if (len == 1) {
      return firstByte;
    }
    long i = 0;
    for (int idx = 0; idx < len-1; idx++) {
      byte b = stream.readByte();
      i = i << 8;
      i = i | (b & 0xFF);
    }
    return (isNegativeVInt(firstByte) ? (i ^ -1L) : i);
  }
135070
def _get_input(self, length):
        """"""
        self._buffer_lock.acquire()
        try:
            if length == -1:
                actualLength = len(self._buffer)
            else:
                actualLength = min(length, len(self._buffer))
            if actualLength:
                data = self._buffer[:actualLength]
                self._buffer = self._buffer[actualLength:]
            else:
                data = bytearray()
            return data
        finally:
            self._buffer_lock.release()
342325
public static byte[] decode( byte[] source, int off, int len )
    {
        int    len34   = len * 3 / 4;
        byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output
        int    outBuffPosn = 0;
        
        byte[] b4        = new byte[4];
        int    b4Posn    = 0;
        int    i         = 0;
        byte   sbiCrop   = 0;
        byte   sbiDecode = 0;
        for( i = 0; i < len; i++ )
        {
            sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits
            sbiDecode = DECODABET[ sbiCrop ];
            
            if( sbiDecode >= WHITE_SPACE_ENC ) // White space, Equals sign or better
            {
                if( sbiDecode >= EQUALS_SIGN_ENC )
                {
                    b4[ b4Posn++ ] = sbiCrop;
                    if( b4Posn > 3 )
                    {
                        outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn );
                        b4Posn = 0;
                        
                        // If that was the equals sign, break out of 'for' loop
                        if( sbiCrop == EQUALS_SIGN )
                            break;
                    }   // end if: quartet built
                    
                }   // end if: equals sign or better
                
            }   // end if: white space, equals sign or better
            else
            {
				LoggerFactory.getDefaultLogger().error( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" );
                return null;
            }   // end else: 
        }   // each input character
                                   
        byte[] out = new byte[ outBuffPosn ];
        System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); 
        return out;
    }