1
zyy
10 days ago 4fefff17528a878d345ff3311c297a66a671b8d6
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
36
37
38
39
40
41
42
package com.yami.trading.huobi.websocket.utils;
 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
 
import com.yami.trading.huobi.websocket.exception.SDKException;
 
public abstract class InternalUtils {
 
  public static byte[] decode(byte[] data) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    decompress(bais, baos);
    baos.flush();
    baos.close();
    bais.close();
    return baos.toByteArray();
  }
 
  private static void decompress(InputStream is, OutputStream os) throws IOException {
    GZIPInputStream gis = new GZIPInputStream(is);
    int count;
    byte[] data = new byte[1024];
    while ((count = gis.read(data, 0, 1024)) != -1) {
      os.write(data, 0, count);
    }
    gis.close();
  }
 
  public static void await(long n) throws SDKException {
    try {
      Thread.sleep(n);
    } catch (InterruptedException e) {
      e.printStackTrace();
      throw new SDKException(SDKException.SYS_ERROR, "Error when sleep");
    }
  }
}