public void compress(byte[] data, int[] keys) throws IOException
	{
		OutputStream stream = new OutputStream();

		byte[] compressedData;
		int length;
		switch (compression)
		{
			case CompressionType.NONE:
				compressedData = data;
				length = compressedData.length;
				break;
			case CompressionType.BZ2:
				compressedData = concat(Ints.toByteArray(data.length), BZip2.compress(data));
				length = compressedData.length - 4;
				break;
			case CompressionType.GZ:
				compressedData = concat(Ints.toByteArray(data.length), GZip.compress(data));
				length = compressedData.length - 4;
				break;
			default:
				throw new RuntimeException("Unknown compression type");
		}

		compressedData = encrypt(compressedData, compressedData.length, keys);

		stream.writeByte(compression);
		stream.writeInt(length);

		stream.writeBytes(compressedData);
		if (revision != -1)
		{
			stream.writeShort(revision);
		}

		this.data = stream.flip();

		Crc32 crc32 = new Crc32();
		crc32.update(this.data, 0, this.data.length - (revision != -1 ? 2 : 0));
		this.crc = crc32.getHash();
	}
@Test
	public void testCompress() throws IOException
	{
		int[] keys = new int[]
		{
			4, 8, 15, 16
		};
		Random random = new Random(42L);
		byte[] data = new byte[1024];
		random.nextBytes(data);

		Container container = new Container(GZ, -1);
		container.compress(data, keys);
		byte[] compressedData = container.data;

		container = Container.decompress(compressedData, keys);
		assertArrayEquals(data, container.data);
	}