java.util.zip.GZIPInputStream#available ( )源码实例Demo

下面列出了java.util.zip.GZIPInputStream#available ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: beatoraja   文件: ScoreData.java
public int[] decodeGhost() {
	try {
		if (ghost == null) {
			return null;
		}
		InputStream input = new ByteArrayInputStream(ghost.getBytes());
		InputStream base64 = Base64.getUrlDecoder().wrap(input);
		GZIPInputStream gzip = new GZIPInputStream(base64);
		if (gzip.available() == 0) {
			return null;
		}
		int[] value = new int[notes];
		for (int i=0; i<value.length; i++) {
			int judge = gzip.read();
			value[i] = judge >= 0 ? judge : 4;
		}
		gzip.close();
		return value;
	} catch (IOException e) {
		return null;
	}
}
 
源代码2 项目: iaf   文件: Misc.java
public static byte[] gunzip(byte[] input) throws DataFormatException, IOException {

		// Create an expandable byte array to hold the decompressed data
		ByteArrayInputStream bis = new ByteArrayInputStream(input);
		GZIPInputStream gz = new GZIPInputStream(bis);
		ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);

		// Decompress the data
		byte[] buf = new byte[1024];
		while (gz.available()>0) {
			 int count = gz.read(buf,0,1024);
			 if (count>0) {
				bos.write(buf, 0, count);
			 }
		}
		bos.close();

		// Get the decompressed data
		return bos.toByteArray();
	}
 
源代码3 项目: ViaRewind   文件: CompressedNBTType.java
public static byte[] decompress(byte[] contentBytes){
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try{
		GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(contentBytes));
		while (stream.available()>0) {
			out.write(stream.read());
		}
	} catch(IOException e){
		throw new RuntimeException(e);
	}
	return out.toByteArray();
}
 
源代码4 项目: jmonkeyengine   文件: GZIPSerializer.java
@SuppressWarnings("unchecked")
@Override
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
    try
    {
        GZIPCompressedMessage result = new GZIPCompressedMessage();

        byte[] byteArray = new byte[data.remaining()];

        data.get(byteArray);

        GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray));
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] tmp = new byte[9012];
        int read;

        while (in.available() > 0 && ((read = in.read(tmp)) > 0)) {
            out.write(tmp, 0, read);
        }

        result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray())));
        return (T)result;
    }
    catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e.toString());
    }
}
 
源代码5 项目: MikuMikuStudio   文件: GZIPSerializer.java
@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
    try
    {
        GZIPCompressedMessage result = new GZIPCompressedMessage();

        byte[] byteArray = new byte[data.remaining()];

        data.get(byteArray);

        GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(byteArray));
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] tmp = new byte[9012];
        int read;

        while (in.available() > 0 && ((read = in.read(tmp)) > 0)) {
            out.write(tmp, 0, read);
        }

        result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray())));
        return (T)result;
    }
    catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e.toString());
    }
}