-
Notifications
You must be signed in to change notification settings - Fork 11
/
Utils.java
35 lines (32 loc) · 1.01 KB
/
Utils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.yeejay.im.library.gifdecode;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class Utils {
public static String toHex(int value, int length) {
String hex = Integer.toHexString(value);
hex = hex.toUpperCase();
if (hex.length() < length) {
while (hex.length() < length)
hex = "0" + hex;
} else if (hex.length() > length) {
hex = hex.substring(hex.length() - length);
}
return hex;
}
public static byte[] streamToBytes(InputStream stream) throws IOException,
OutOfMemoryError {
byte[] buff = new byte[1024];
int read;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
while ((read = stream.read(buff)) != -1) {
bao.write(buff, 0, read);
}
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
return bao.toByteArray();
}
}