All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.java.truelicense.core.V1Compression Maven / Gradle / Ivy

Go to download

The TrueLicense Core module provides essential functionality for license management.

There is a newer version: 2.6.6
Show newest version
/*
 * Copyright (C) 2005-2013 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package net.java.truelicense.core;

import java.io.*;
import java.util.zip.*;
import javax.annotation.concurrent.Immutable;
import net.java.truelicense.core.io.*;

/**
 * The compression for V1 format license keys.
 *
 * @author Christian Schlichtherle
 */
@Immutable
final class V1Compression implements Transformation {

    @Override public Sink apply(final Sink sink) {
        return new Sink() {
            @Override public OutputStream output() throws IOException {
                final OutputStream out = sink.output();
                try {
                    return new GZIPOutputStream(out, Store.BUFSIZE);
                } catch (final IOException ex) { // TODO: make this a Throwable for Java 7
                    try { out.close(); }
                    finally { throw ex; }
                }
            }
        };
    }

    @Override public Source unapply(final Source source) {
        return new Source() {
            @Override public InputStream input() throws IOException {
                final InputStream in = source.input();
                try {
                    return new GZIPInputStream(in, Store.BUFSIZE);
                } catch (final IOException ex) { // TODO: make this a Throwable for Java 7
                    try { in.close(); }
                    finally { throw ex; }
                }
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy