/*
 * Copyright (c) Codice Foundation
 *
 * This 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, either version 3 of the
 * License, or any later version.
 *
 * This program 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. A copy of the GNU Lesser General Public License
 * is distributed along with this program and can be found at
 * <http://www.gnu.org/licenses/lgpl.html>.
 *
 */
package org.codice.imaging.nitf.core.impl;

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

import org.codice.imaging.nitf.core.DataSource;
import org.codice.imaging.nitf.core.common.NitfFormatException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A NitfWriter implementation that works on streaming data.
 */
public class NitfOutputStreamWriter extends SharedNitfWriter {

    private static final Logger LOGGER = LoggerFactory.getLogger(NitfFileWriter.class);

    /**
     * Construct a stream-based NITF writer.
     *
     * @param nitfDataSource the source of data to be written out.
     * @param outputStream the output stream to write the data to.
     */
    public NitfOutputStreamWriter(final DataSource nitfDataSource, final OutputStream outputStream) {
        super(nitfDataSource);
        mOutput = new DataOutputStream(outputStream);
    }

    @Override
    public final void write() {
        try {
            writeData();
        } catch (NitfFormatException | IOException ex) {
            LOGGER.error("Could not write {}", ex.getMessage());
        }
    }

}
