Code example for ByteArrayOutputStream

Methods: toByteArray

0
 * Useful base class for stream-based compression strategies. 
 */ 
public abstract class StreamCompressionStrategy implements CompressionStrategy { 
 
    public byte[] deflate(byte[] data) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStream gos = wrapOutputStream(bos);
        gos.write(data);
        gos.close();
        return bos.toByteArray();
    } 
 
    protected abstract OutputStream wrapOutputStream(OutputStream underlying) throws IOException;
 
    protected abstract InputStream wrapInputStream(InputStream underlying) throws IOException;
 
    public byte[] inflate(byte[] data) throws IOException {
        InputStream is = wrapInputStream(new ByteArrayInputStream(data));
        byte[] inflated = IOUtils.toByteArray(is);
        is.close();
        return inflated;