All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xbib.io.compress.xz.common.EncoderUtil Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package org.xbib.io.compress.xz.common;

import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.CRC32;

/**
 *
 */
public class EncoderUtil extends Util {
    public static void writeCRC32(OutputStream out, byte[] buf)
            throws IOException {
        CRC32 crc32 = new CRC32();
        crc32.update(buf);
        long value = crc32.getValue();

        for (int i = 0; i < 4; ++i) {
            out.write((byte) (value >>> (i * 8)));
        }
    }

    public static void encodeVLI(OutputStream out, long num)
            throws IOException {
        while (num >= 0x80) {
            out.write((byte) (num | 0x80));
            num >>>= 7;
        }

        out.write((byte) num);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy