package com.jscape.util.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author Alex Usun
 */
public interface CompressionService {

    CompressionService NULL_SERVICE = new CompressionService() {
        @Override
        public InputStream compress(InputStream base)
                throws OperationException {
            return base;
        }

        @Override
        public OutputStream decompress(OutputStream base)
                throws OperationException {
            return base;
        }
    };

    InputStream compress(InputStream base)
            throws OperationException;

    OutputStream decompress(OutputStream base)
            throws OperationException;

    class OperationException
            extends IOException {

        public OperationException() {
        }

        public OperationException(String message) {
            super(message);
        }

        public OperationException(String message, Throwable cause) {
            super(message, cause);
        }

        public OperationException(Throwable cause) {
            super(cause.getMessage() != null ? cause.getMessage() : cause.toString(), cause);
        }
    }

}
