Line | |
---|
1 | /*
|
---|
2 | * EncoderUtil
|
---|
3 | *
|
---|
4 | * Author: Lasse Collin <lasse.collin@tukaani.org>
|
---|
5 | *
|
---|
6 | * This file has been put into the public domain.
|
---|
7 | * You can do whatever you want with this file.
|
---|
8 | */
|
---|
9 |
|
---|
10 | package org.tukaani.xz.common;
|
---|
11 |
|
---|
12 | import java.io.OutputStream;
|
---|
13 | import java.io.IOException;
|
---|
14 | import java.util.zip.CRC32;
|
---|
15 |
|
---|
16 | public class EncoderUtil extends Util {
|
---|
17 | public static void writeCRC32(OutputStream out, byte[] buf)
|
---|
18 | throws IOException {
|
---|
19 | CRC32 crc32 = new CRC32();
|
---|
20 | crc32.update(buf);
|
---|
21 | long value = crc32.getValue();
|
---|
22 |
|
---|
23 | for (int i = 0; i < 4; ++i)
|
---|
24 | out.write((byte)(value >>> (i * 8)));
|
---|
25 | }
|
---|
26 |
|
---|
27 | public static void encodeVLI(OutputStream out, long num)
|
---|
28 | throws IOException {
|
---|
29 | while (num >= 0x80) {
|
---|
30 | out.write((byte)(num | 0x80));
|
---|
31 | num >>>= 7;
|
---|
32 | }
|
---|
33 |
|
---|
34 | out.write((byte)num);
|
---|
35 | }
|
---|
36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.