I have seen this before in the encodes and decodes before where we do the same operation over and over again.

Can we refactor this logic to a utility method such as

public static byte[] decodeNextValue(DataInputStream din) {
    int len = din.readInt();
    byte[] retVal = new byte[len];
    din.read(retVal);
    return retVal;
}

Ditto for the encoding.