<commit_before>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2005-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.coverage.grid.io;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.stream.ImageOutputStream;
import org.geotools.util.factory.GeoTools;
import org.geotools.util.factory.Hints;
import org.geotools.util.logging.Logging;
import org.opengis.coverage.grid.GridCoverageWriter;

/**
 * An {@link AbstractGridCoverageWriter} is the base class for all {@link GridCoverageWriter}
 * implementations in GeoTools toolkit.
 *
 * <p>We expect it to become the place where to move functionalities common to all {@link
 * GridCoverageWriter}.
 *
 * @author <NAME>
 * @since 2.3.x
 */
public abstract class AbstractGridCoverageWriter implements GridCoverageWriter {

    /** The {@link Logger} for this {@link AbstractGridCoverageWriter}. */
    private static final Logger LOGGER = Logging.getLogger(AbstractGridCoverageWriter.class);

    /** the destination object where we will do the writing */
    protected Object destination;

    /** Hints to be used for the writing process. */
    protected Hints hints = GeoTools.getDefaultHints();

    /** The destination {@link ImageOutputStream}. */
    protected ImageOutputStream outStream = null;

    /** Default constructor for an {@link AbstractGridCoverageWriter}. */
    public AbstractGridCoverageWriter() {}

    /** Releases resources held by this {@link AbstractGridCoverageWriter}. */
    public void dispose() {
        if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Disposing writer:" + destination);

        if (outStream != null) {
            try {
                outStream.flush();

            } catch (IOException e) {

            } finally {
                try {
                    outStream.close();
                } catch (Throwable e) {

                }
            }
        }
    }

    /**
     * (non-Javadoc)
     *
     * @see org.opengis.coverage.grid.GridCoverageWriter#getDestination()
     */
    public Object getDestination() {
        return destination;
    }<commit_msg>GEOT-6411, Have AbstractGridCoverageWriter release both output stream and destination on dispose()<commit_after>/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2005-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.coverage.grid.io;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.stream.ImageOutputStream;
import org.geotools.util.factory.GeoTools;
import org.geotools.util.factory.Hints;
import org.geotools.util.logging.Logging;
import org.opengis.coverage.grid.GridCoverageWriter;

/**
 * An {@link AbstractGridCoverageWriter} is the base class for all {@link GridCoverageWriter}
 * implementations in GeoTools toolkit.
 *
 * <p>We expect it to become the place where to move functionalities common to all {@link
 * GridCoverageWriter}.
 *
 * @author <NAME>
 * @since 2.3.x
 */
public abstract class AbstractGridCoverageWriter implements GridCoverageWriter {

    /** The {@link Logger} for this {@link AbstractGridCoverageWriter}. */
    private static final Logger LOGGER = Logging.getLogger(AbstractGridCoverageWriter.class);

    /** the destination object where we will do the writing */
    protected Object destination;

    /** Hints to be used for the writing process. */
    protected Hints hints = GeoTools.getDefaultHints();

    /** The destination {@link ImageOutputStream}. */
    protected ImageOutputStream outStream = null;

    /** Default constructor for an {@link AbstractGridCoverageWriter}. */
    public AbstractGridCoverageWriter() {}

    /** Releases resources held by this {@link AbstractGridCoverageWriter}. */
    public void dispose() {
        if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Disposing writer:" + destination);

        if (outStream != null) {
            try {
                outStream.flush();

            } catch (IOException e) {

            } finally {
                try {
                    outStream.close();
                } catch (Throwable e) {

                }
                outStream = null;
                destination = null;
            }
        }
    }

    /**
     * (non-Javadoc)
     *
     * @see org.opengis.coverage.grid.GridCoverageWriter#getDestination()
     */
    public Object getDestination() {
        return destination;
    }
{'fraction_non_alphanumeric': 0.09216921692169217, 'fraction_numerical': 0.005040504050405041, 'mean_word_length': 2.815934065934066, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6027753', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1472, 'n_words': 490}