encodes a byte array to a String

@param barr
@return encoded String
18140
public static String encode(byte barr[]) {
	StringBuilder rtn = new StringBuilder();
	int len = barr.length;
	int read = 0;
	boolean stop = false;
	byte b = 0;
	int offset = 0;

	do {
	    int left = len - read;
	    if (left == 0) stop = true;

	    if (left <= 45) b = (byte) left;
	    else b = 45;

	    rtn.append(_enc(b));
	    for (int i = 0; i < b; i += 3) {
		if (len - offset < 3) {
		    byte padding[] = new byte[3];
		    for (int z = 0; offset + z < len; z++)
			padding[z] = barr[offset + z];
		    encodeBytes(padding, 0, rtn);
		}
		else {
		    encodeBytes(barr, offset, rtn);
		}
		offset += 3;
	    }

	    rtn.append('\n');
	    read += b;
	    if (b < 45) stop = true;
	}
	while (!stop);
	return rtn.toString();
    }
69115
public static String encode(byte[] from) {
        StringBuilder to = new StringBuilder((int) (from.length * 1.34) + 3);
        int num = 0;
        char currentByte = 0;
        for (int i = 0; i < from.length; i++) {
            num = num % 8;
            while (num < 8) {
                switch (num) {
                    case 0:
                        currentByte = (char) (from[i] & lead6byte);
                        currentByte = (char) (currentByte >>> 2);
                        break;
                    case 2:
                        currentByte = (char) (from[i] & last6byte);
                        break;
                    case 4:
                        currentByte = (char) (from[i] & last4byte);
                        currentByte = (char) (currentByte << 2);
                        if ((i + 1) < from.length) {
                            currentByte |= (from[i + 1] & lead2byte) >>> 6;
                        }
                        break;
                    case 6:
                        currentByte = (char) (from[i] & last2byte);
                        currentByte = (char) (currentByte << 4);
                        if ((i + 1) < from.length) {
                            currentByte |= (from[i + 1] & lead4byte) >>> 4;
                        }
                        break;
                    default:
                        break;
                }
                to.append(encodeTable[currentByte]);
                num += 6;
            }
        }
        if (to.length() % 4 != 0) {
            for (int i = 4 - to.length() % 4; i > 0; i--) {
                to.append("=");
            }
        }
        return to.toString();
    }
1331245
@SneakyThrows
    public static String decodeByteArrayToString(final byte[] bytes) {
        @Cleanup
        val bais = new ByteArrayInputStream(bytes);
        @Cleanup
        val baos = new ByteArrayOutputStream();
        val buf = new byte[bytes.length];
        try (val iis = new InflaterInputStream(bais)) {
            var count = iis.read(buf);
            while (count != -1) {
                baos.write(buf, 0, count);
                count = iis.read(buf);
            }
            return new String(baos.toByteArray(), StandardCharsets.UTF_8);
        } catch (final Exception e) {
            LOGGER.error("Base64 decoding failed", e);
            return null;
        }
    }
97611
public String encode(String str) throws IOException {
    	byte[] array;
    	try { 
    		array = str.getBytes(encoding);
    	} catch (IOException e) {
    		array = str.getBytes(); // take default
    	}
    	// Calculate expected size to avoid any buffer expansion copies within the ByteArrayOutput code
    	ByteArrayOutputStream baos = new ByteArrayOutputStream((int)(array.length*1.363)); // account for 4 bytes for 3 and a byte or two more
    	
    	encode(new ByteArrayInputStream(array),baos);
    	return baos.toString(encoding);
    }
1194329
@Override
	public String encodeAsString() {
		if(message.size == 0) return "";

		return new String(Base64Coder.encode(message.array, message.size));
	}
1091100
public static String encode(byte[] data) {
        if (data.length == 0) {
            return "";
        }
        final byte[] bytes = copyOfRange(data, 0, data.length);
        // Count leading zeroes.
        int zeroCount = 0;
        while (zeroCount < bytes.length && bytes[zeroCount] == 0) {
            ++zeroCount;
        }
        // The actual encoding.
        byte[] temp = new byte[bytes.length * 2];
        int j = temp.length;

        int startAt = zeroCount;
        while (startAt < bytes.length) {
            byte mod = divmod58(bytes, startAt);
            if (bytes[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 ApplicationException(e);  // Cannot happen.
        }
    }
1238102
public final String encodeBytes(byte[] bytes) {
        logger.entry();
        String base64String = Base64Utils.encode(bytes);
        logger.exit();
        return base64String;
    }
203653
public static String encode(byte[] in) {
        if (in == null) {
            return null;
        }
        return encode(in, 0, in.length);
    }
410747
public static String encode(byte[] bytes)
    {
        StringBuilder sb = new StringBuilder(bytes.length << 1);
        for (byte aByte : bytes)
        {
            sb.append(convertDigit(aByte >> 4));
            sb.append(convertDigit(aByte & 0x0f));
        }
        return sb.toString();
    }
791616
String encodeBinary(byte[] data){
        if (data == null) return null;
        return Base64.encodeToString(data,Base64.URL_SAFE|Base64.NO_WRAP);
    }
293238
public static StringBuffer encode(byte[] data)
	{
		int rem = data.length % 3;
		int num = data.length / 3;
		StringBuffer result = new StringBuffer();
		int p = 0;
		// int c=0;

		for (int i = 0; i < num; i++)
		{
			int b1 = (data[p] & 0xfc) >> 2;
			int b2 = (data[p] & 0x03) << 4 | (data[p + 1] & 0xf0) >> 4;
			int b3 = (data[p + 1] & 0x0f) << 2 | (data[p + 2] & 0xc0) >> 6;
			int b4 = data[p + 2] & 0x3f;

			result.append(b64encode(b1));
			result.append(b64encode(b2));
			result.append(b64encode(b3));
			result.append(b64encode(b4));

			p += 3;
			// c += 4;
		}

		switch (rem)
		{
			case 0:
				break;

			case 1:
			{
				int b1 = (data[p] & 0xfc) >> 2;
				int b2 = (data[p] & 0x03) << 4;

				result.append(b64encode(b1));
				result.append(b64encode(b2));
				result.append('=');
				result.append('=');
				break;
			}

			case 2:
			{
				int b1 = (data[p] & 0xfc) >> 2;
				int b2 = (data[p] & 0x03) << 4 | (data[p + 1] & 0xf0) >> 4;
				int b3 = (data[p + 1] & 0x0f) << 2;

				result.append(b64encode(b1));
				result.append(b64encode(b2));
				result.append(b64encode(b3));
				result.append('=');
				break;
			}
		}

		return result;
	}
860219
@Pure
	@Inline(value = "Base64Coder.encode($1, ($1).length)", imported = {Base64Coder.class})
	public static char[] encode(byte[] in) {
		return encode(in, in.length);
	}
297892
@Override
	public ByteArray encodeAsByteArray() {
		if(message.isEmpty()) return ByteArray.EMPTY_BYTE_ARRAY;

		return new ByteArray(message.getBytes(CHARSET));
	}
1272528
public static String encodeByteArray(byte[] byteArray) {
		try {
			return new String(Base64.encodeBase64(byteArray), UTF8_ENCODING);
		} catch(UnsupportedEncodingException e) {
			throw new MappingException("Could not encode byteArray to UTF8 encoding", e);
		}
	}
64186
def encode_ber(value, ber_length=0):
    
    if not ber_length:
        if value < 127: # 1 byte case
            return bytearray([value])
        ber_length = 1
        while value >= pow(2, 8*ber_length):
            ber_length += 1
        ber_length += 1


    ber = bytearray(ber_length)
    ber[0] = 127 + ber_length #ber length byte
    for i in range(1, ber_length):
        ber[i] = (value >> (8 * (ber_length - 1 - i))) & 255
    return ber
320995
public void encodeBinary(byte[] b) throws IOException {
		encodeUnsignedInteger(b.length);
		encode(b, 0, b.length);
	}
840063
public static String byteArrayToHexString(byte[] b) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < b.length; i++) {
			sb.append(byteToHexString(b[i]));
		}
		return new String(sb);
	}