/**
 * Copyright (c) 2017, Stephan Saalfeld
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package org.janelia.saalfeldlab.n5;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.Deflater;

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipParameters;
import org.janelia.saalfeldlab.n5.Compression.CompressionType;

@CompressionType("gzip")
public class GzipCompression implements DefaultBlockReader, DefaultBlockWriter, Compression {

	private static final long serialVersionUID = 8630847239813334263L;

	@CompressionParameter
	private final int level;

	private final transient GzipParameters parameters = new GzipParameters();

	public GzipCompression(final int level) {

		this.level = level;
	}

	public GzipCompression() {

		this(Deflater.DEFAULT_COMPRESSION);
	}

	@Override
	public InputStream getInputStream(final InputStream in) throws IOException {

		return new GzipCompressorInputStream(in);
	}

	@Override
	public OutputStream getOutputStream(final OutputStream out) throws IOException {

		parameters.setCompressionLevel(level);
		return new GzipCompressorOutputStream(out, parameters);
	}

	@Override
	public GzipCompression getReader() {

		return this;
	}

	@Override
	public GzipCompression getWriter() {

		return this;
	}
}

@@ -1478,27 +1478,128 @@
 ava.io.O
-utputStream
+bjectInputStream;%0Aimport java.io.OutputStream;%0Aimport java.lang.reflect.Field;%0Aimport java.lang.reflect.Modifier
 ;%0Aimport
@@ -2842,11 +2842,818 @@
 this;%0A%09%7D
+%0A%0A%09private void readObject(final ObjectInputStream in) throws Exception %7B%0A%0A%09%09in.defaultReadObject();%0A%0A%09%09final Field modifiersField = Field.class.getDeclaredField(%22modifiers%22);%0A%09%09final boolean isModifiersAccessible = modifiersField.isAccessible();%0A%09%09modifiersField.setAccessible(true);%0A%09%09final Field parametersField = getClass().getDeclaredField(%22parameters%22);%0A%09%09final boolean isFieldAccessible = parametersField.isAccessible();%0A%09%09parametersField.setAccessible(true);%0A%09%09final int modifiers = parametersField.getModifiers();%0A%09%09modifiersField.setInt(parametersField, modifiers & ~Modifier.FINAL);%0A%09%09parametersField.set(this, new GzipParameters());%0A%09%09modifiersField.setInt(parametersField, modifiers);%0A%09%09parametersField.setAccessible(isFieldAccessible);%0A%09%09modifiersField.setAccessible(isModifiersAccessible);%0A%09%7D
 %0A%7D%0A

Initialize GzipCompression parameters after deserialization (#26)