package com.jscape.inet.ssh.protocol.v2.marshaling.algorithms;

import com.jscape.util.SuppressObfuscation;

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

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

    Compression NULL = new Compression() {
        @Override
        public int apply(byte[] data, int offset, int length, OutputStream out)
                throws OperationException {
            try {
                out.write(data, offset, length);
                return length;
            } catch (IOException e) {
                throw new OperationException(e);
            }
        }
    };

    int apply(byte[] data, int offset, int length, OutputStream out)
            throws OperationException;

    @SuppressObfuscation
    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);
        }
    }

}
