Encodes a string into Base64 format.
No blanks or line breaks are inserted.

@param string  a String to be encoded.
@return   A String with the Base64 encoded data.
325596
@Pure
	@Inline(value = "new String(Base64Coder.encode(($1).getBytes()))", imported = {Base64Coder.class})
	public static String encodeString(String string) {
		return new String(encode(string.getBytes()));
	}
36314
public String encode(String value) {
    if (value == null) { return null; }
    StringBuilder buffer = new StringBuilder();
    buffer.append(Prefix);
    buffer.append(charset);
    buffer.append(Sep);
    buffer.append(getEncoding());
    buffer.append(Sep);
    buffer.append(new String(Base64.encode(value.getBytes(charset))));
    buffer.append(Postfix);
    return buffer.toString();
  }
411978
public static String encodeBase64(final String data) {
        return Base64.encodeBase64String(data.getBytes(StandardCharsets.UTF_8));
    }
1074541
public static String encode(byte[] bytes) {
		int bytesLength = bytes.length;
		int base64Length = (bytesLength * 4 + 2) / 3; // base64 encoded string length, without padding

		StringBuilder base64Builder = new StringBuilder();
		int bytesIndex = 0;

		while (bytesIndex < bytesLength) {
			int i0 = bytes[bytesIndex++] & 0xff;
			int i1 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;
			int i2 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;

			int o0 = i0 >>> 2;
			int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
			int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
			int o3 = i2 & 0x3F;

			base64Builder.append(NIBLES_2_CHARS[o0]);
			base64Builder.append(NIBLES_2_CHARS[o1]);
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o2] : '=');
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o3] : '=');
		}

		return base64Builder.toString();
	}
1013477
public static String encodeBase64(byte[] rawData, int lineLength) {
		if (rawData == null) {
			return "";
		}
		StringBuffer retval = new StringBuffer();
		int i = 0;
		int n = 0;
		for (; i < rawData.length - 2; i += 3) {
			if (lineLength > 0 && i > 0 && i % lineLength == 0) {
				retval.append("\n");
			}
			//n is a 32 bit number
			//shift all the way to left first to get rid of sign
			//  3.shift last 8 bits to left    2.shift next 8 bits left of first 1. start here with last 8 bits shifted into int
			n = (((rawData[i] << 24) >>> 8) + ((rawData[i + 1] << 24) >>> 16) + ((rawData[i + 2] << 24) >>> 24));
			//this results in a 24 bit number (stored in 32 bit int)
			//of which 4 chunks of 6 bits are used to pick characters of base64Chars
			retval.append(base64Chars.charAt((n >>> 18) & 63));
			retval.append(base64Chars.charAt((n >>> 12) & 63));
			retval.append(base64Chars.charAt((n >>> 6) & 63));
			retval.append(base64Chars.charAt(n & 63));
		}
		//finish according to spec
		if (i + 1 == rawData.length) {
			n = ((rawData[i] << 24) >>> 8);

			retval.append(base64Chars.charAt((n >>> 18) & 63));
			retval.append(base64Chars.charAt((n >>> 12) & 63));
			retval.append("==");
		}
		if (i + 2 == rawData.length) {
			n = ((rawData[i] << 24) >>> 8) + ((rawData[i + 1] << 24) >>> 16);

			retval.append(base64Chars.charAt((n >>> 18) & 63));
			retval.append(base64Chars.charAt((n >>> 12) & 63));
			retval.append(base64Chars.charAt((n >>> 6) & 63));
			retval.append('=');
		}

		return retval.toString();
	}
981225
public function encodeString(string $string, ?string $charset = 'utf-8', int $firstLineOffset = 0, int $maxLineLength = 0): string
    {
        if (0 >= $maxLineLength || 76 < $maxLineLength) {
            $maxLineLength = 76;
        }

        $encodedString = base64_encode($string);
        $firstLine = '';
        if (0 !== $firstLineOffset) {
            $firstLine = substr($encodedString, 0, $maxLineLength - $firstLineOffset)."\r\n";
            $encodedString = substr($encodedString, $maxLineLength - $firstLineOffset);
        }

        return $firstLine.trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
    }
990958
public static String encode(String str) {
		StringBuilder sb = new StringBuilder();
		char[] arr = str.toCharArray();
		for (char c : arr) {
			String s4 = Integer.toHexString(c);
			sb.append(s4);
		}
		return sb.toString();
	}
97619
protected function encodeDate($string = '')
    {
        // maybe has to be rewritten for multibyte...
        $length        = strlen($string);
        $encodedString = '';

        for ($i = 0; $i < $length; ++$i) {
            $encodedString .= '\\'.$string[$i];
        }

        // return encoded string
        return $encodedString;
    }
781607
private function isBase64($string) 
    {
        $decoded_data = base64_decode($string, true);
        $encoded_data = base64_encode($decoded_data);
        if ($encoded_data != $string) {
            return false;
        }
        return true;
    }
882586
@Deprecated
    public static String encodeBASE64(String value) {
        return new String(Base64.encode(value.getBytes(Charsets.UTF_8)));
    }
11345
public function encodeString(string $string, ?string $charset = 'utf-8', int $firstLineOffset = 0, int $maxLineLength = 0): string
    {
        $lines = [];
        $lineCount = 0;
        $lines[] = '';
        $currentLine = &$lines[$lineCount++];

        if (0 >= $maxLineLength) {
            $maxLineLength = 75;
        }

        $charStream = new CharacterStream($string, $charset);
        $thisLineLength = $maxLineLength - $firstLineOffset;

        while (null !== $char = $charStream->read(4)) {
            $encodedChar = rawurlencode($char);
            if (0 !== \strlen($currentLine) && \strlen($currentLine.$encodedChar) > $thisLineLength) {
                $lines[] = '';
                $currentLine = &$lines[$lineCount++];
                $thisLineLength = $maxLineLength;
            }
            $currentLine .= $encodedChar;
        }

        return implode("\r\n", $lines);
    }
804578
static String base64(byte[] data) {
        ByteBuf encodedData = Unpooled.wrappedBuffer(data);
        ByteBuf encoded = Base64.encode(encodedData);
        String encodedString = encoded.toString(CharsetUtil.UTF_8);
        encoded.release();
        return encodedString;
    }
1182964
public static String encode( String string ) {
        byte[] bytes;
        try {
            bytes = string.getBytes(PREFERRED_ENCODING);
        } catch( UnsupportedEncodingException uee ) {
            bytes = string.getBytes();
        }
        return encodeBytes(bytes);
    }
551037
@Override
	public String encodeAsString() throws IOException {
		ByteArray byteArray = encodeAsByteArray();
		if(byteArray.size == 0) return "";
		return new String(Base64Coder.encode(byteArray.array, byteArray.size));
	}
1194329
@Override
	public String encodeAsString() {
		if(message.size == 0) return "";

		return new String(Base64Coder.encode(message.array, message.size));
	}
633563
public static String encode (String string)
    {
        if (string == null)
        {
            return "";
        }

        StringBuilder sb = null;
        char c;
        for (int i = 0; i < string.length (); ++i)
        {
            c = string.charAt(i);
            if (((int)c) >= 0x80)
            {
                if( sb == null )
                {
                    sb = new StringBuilder( string.length()+4 );
                    sb.append( string.substring(0,i) );
                }
                //encode all non basic latin characters
                sb.append("&#");
                sb.append((int)c);
                sb.append(";");
            }
            else if( sb != null )
            {
                sb.append(c);
            }
        }

        return sb != null ? sb.toString() : string;
    }
423795
private static function encodeString($string)
    {
        $length = mb_strlen($string, self::STRING_ENCODING);

        $data = self::encodeIntValue(MajorType::UTF8_STRING, $length);

        for ($i = 0; $i < $length; $i++)
        {
            $mbchar = mb_substr($string, $i, 1);
            $chars = strlen($mbchar);
            for ($j = 0; $j < $chars; $j++)
            {
                $data .= pack(PackFormat::UINT_8, ord($mbchar[$j]));
            }
        }

        return $data;
    }