Java Utililty Methods Byte Array Encode

List of utility methods to do Byte Array Encode

Description

The list of methods to do Byte Array Encode are organized into topic(s).

Method

byte[]encode(byte[] message)
Apply DEFLATE encoding
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.DEFLATED, true);
DeflaterOutputStream deflaterStream = new DeflaterOutputStream(baos, deflater);
deflaterStream.write(message);
deflaterStream.finish();
return baos.toByteArray();
Stringencode(byte[] rawData)
encode
StringBuilder hexText = new StringBuilder();
String initialHex = null;
int initHexLength = 0;
for (int i = 0; i < rawData.length; i++) {
    int positiveValue = rawData[i] & 0x000000FF;
    initialHex = Integer.toHexString(positiveValue);
    initHexLength = initialHex.length();
    while (initHexLength++ < 2) {
...
Stringencode(byte[] source)
Encodes a byte array into Base64 notation.
byte[] encoded = encodeBytesToBytes(source, source.length);
try {
    return new String(encoded, "US-ASCII");
} catch (java.io.UnsupportedEncodingException uue) {
    return new String(encoded);
voidencode(String prefix, byte[] buf, ZipOutputStream zos, File[] files)
encode
for (File f : files) {
    try {
        if (f.isDirectory()) {
            encode(prefix, buf, zos, f.listFiles());
        } else {
            ZipEntry entry = new ZipEntry(f.getPath().replace(prefix, "").replace('\\', '/'));
            zos.putNextEntry(entry);
            try (InputStream is = new BufferedInputStream(new FileInputStream(f))) {
...
StringencodeAsUtf8(byte[] bytes)
encode As Utf
try {
    return new String(bytes, UTF_8);
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
voidencodeBitString(byte[] in, OutputStream os)
encode Bit String
os.write(BIT_STRING);
writeLength(in.length + 1, os);
os.write(0);
os.write(in);
voidencodeByteArray(DataOutputStream out, byte[] bytes)
encode Byte Array
if (bytes == null) {
    out.writeInt(-1);
    return;
out.writeInt(bytes.length);
out.write(bytes);
StringencodeBytes(byte[] source, int off, int len)
Encodes a byte array into Base64 notation.
byte[] encoded = encodeBytesToBytes(source, off, len);
try {
    return new String(encoded, PREFERRED_ENCODING);
} catch (UnsupportedEncodingException uee) {
    return new String(encoded);
byte[]encodeCompositeAlways(List bytesList)
makes composite column name or row key
byte[] encBytes;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for (byte[] bytes : bytesList) {
    bos.write((byte) ((bytes.length >> 8) & 0xFF));
    bos.write((byte) (bytes.length & 0xFF));
    for (int j = 0; j < bytes.length; j++) {
        bos.write(bytes[j] & 0xFF);
    bos.write((byte) 0);
encBytes = bos.toByteArray();
return encBytes;
StringencodeDataWithCharsetInMetaTag(byte[] data)
encode Data With Charset In Meta Tag
Matcher m = characterEncodingPattern.matcher(new String(data, "ISO-8859-1"));
if (m.find()) {
    String foundCharset = m.group(1);
    if (foundCharset.toLowerCase().equals("iso-8859-1")) {
        logger.info("ISO-8859-1 found in meta tag, usind windows-1252 instead");
        foundCharset = DEFAULT_CHARACTER_ENCODING;
    return new String(data, foundCharset);
...