Java Code Examples for java.util.zip.GZIPInputStream#available()

The following examples show how to use java.util.zip.GZIPInputStream#available() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScoreData.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example 2
Source File: Misc.java    From iaf with Apache License 2.0 6 votes vote down vote up
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();
	}
 
Example 3
Source File: CompressedNBTType.java    From ViaRewind with MIT License 5 votes vote down vote up
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();
}
 
Example 4
Source File: GZIPSerializer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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());
    }
}
 
Example 5
Source File: GZIPSerializer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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());
    }
}