| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.tukaani.xz.common; |
| 6 |
|
| 7 |
import java.io.OutputStream; |
| 8 |
import java.io.IOException; |
| 9 |
import java.util.zip.CRC32; |
| 10 |
|
| 11 |
public class EncoderUtil extends Util { |
| 12 |
public static void writeCRC32(OutputStream out, byte[] buf) |
| 13 |
throws IOException { |
| 14 |
CRC32 crc32 = new CRC32(); |
| 15 |
crc32.update(buf); |
| 16 |
long value = crc32.getValue(); |
| 17 |
|
| 18 |
for (int i = 0; i < 4; ++i) |
| 19 |
out.write((byte)(value >>> (i * 8))); |
| 20 |
} |
| 21 |
|
| 22 |
public static void encodeVLI(OutputStream out, long num) |
| 23 |
throws IOException { |
| 24 |
while (num >= 0x80) { |
| 25 |
out.write((byte)(num | 0x80)); |
| 26 |
num >>>= 7; |
| 27 |
} |
| 28 |
|
| 29 |
out.write((byte)num); |
| 30 |
} |
| 31 |
} |