private static void generateUnpack(FileWriter fw, int bitWidth, int batch, boolean isLong, boolean msbFirst, boolean useByteArray)
            throws IOException {
        final String variableType = isLong ? VARIABLE_TYPE_FOR_LONG : VARIABLE_TYPE_FOR_INT;
        final String bufferDataType = useByteArray ? "byte[]" : "ByteBuffer";

        fw.append("    public final void unpack" + (batch * 8) + "Values(final " + bufferDataType + " in, "
                + "final int inPos, final " + variableType + "[] out, final int outPos) {\n");

        if (bitWidth > 0) {
            String maskSuffix = isLong ? "L" : "";
            for (int valueIndex = 0; valueIndex < (batch * 8); ++valueIndex) {
                fw.append("      out[" + align(valueIndex, 2) + " + outPos] =\n");

                int startIndex = valueIndex * bitWidth / 8;
                int endIndex = paddedByteCountFromBits((valueIndex + 1) * bitWidth);

                for (int byteIndex = startIndex; byteIndex < endIndex; byteIndex++) {
                    if (byteIndex == startIndex) {
                        fw.append("          ");
                    } else {
                        fw.append("\n        | ");
                    }

                    ShiftMask shiftMask = getShift(fw, bitWidth, isLong, msbFirst, byteIndex, valueIndex);

                    String shiftString = ""; // when shift == 0
                    if (shiftMask.shift < 0) {
                        shiftString = ">>  " + (-shiftMask.shift);
                    } else if (shiftMask.shift > 0) {
                        shiftString = "<<  " + shiftMask.shift;
                    }

                    final String byteAccess;
                    if (useByteArray) {
                        byteAccess = "in[" + align(byteIndex, 2) + " + inPos]";
                    } else {
                        // use ByteBuffer#get(index) method
                        byteAccess = "in.get(" + align(byteIndex, 2) + " + inPos)";
                    }

                    // Shift the wanted bits to the least significant position and mask them knowing how many bits to get.
                    fw.append(" ((((" + variableType + ")" + byteAccess + ") " + shiftString +
                            ") & " + shiftMask.mask + maskSuffix + ")");
                }
                fw.append(";\n");
            }
        }
        fw.append("    }\n");
    }
\n");
        if (msbFirst) {
            fw.append(" * Packs from the Most Significant Bit first\n");
        } else {
            fw.append(" * Packs from the Least Significant Bit first\n");
        }
        fw.append(" * \n");
        fw.append(" * @author automatically generated\n");
        fw.append(" * @see ByteBasedBitPackingGenerator\n");
        fw.append(" *\n");
        fw.append("
indexr-codegen/src/main/java/io/indexr/vlt/codec/pack/PackingClassGen.java