JCLOUDS-885: Add utility to gzip data

Useful for integration tests which expect gzip data.
This commit is contained in:
Andrew Gaul 2015-09-28 19:56:26 -07:00
parent 2e7de9f850
commit 9342cad895
1 changed files with 10 additions and 0 deletions

View File

@ -16,9 +16,11 @@
*/
package org.jclouds.utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import java.util.zip.GZIPOutputStream;
import com.google.common.io.ByteSource;
@ -90,4 +92,12 @@ public class TestUtils {
closed = true;
}
}
public static byte[] gzip(byte[] data) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length);
GZIPOutputStream gos = new GZIPOutputStream(baos);
gos.write(data, 0, data.length);
gos.finish();
return baos.toByteArray();
}
}