/*
 * 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.fluent;

import java.io.IOException;
import java.io.OutputStream;
import java.util.function.Supplier;

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

/**
 * Provides methods for writing a NITF to a java.io.File or java.io.OutputStream.  Instances of
 * this class will maintain state for a single OutputStream.  Expected usage is that either
 * outputStream() or file() will be called, not both. Calling them both will have the same effect
 * as calling only the last one.  Calling write() before outputStream() or file() will result in
 * no operation being performed.
 */
public class NitfWriterFlow {
    private Supplier<OutputStream> streamSupplier;

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

    /**
     * Sets the OutputStream that a call to write() will write to.  Calling this method multiple
     * times, or calling file() after outputStream() will overwrite the previous value.
     *
     * @param outputStreamSupplier a Supplier for the OutputStream to write the NITF to.
     * @return this NitfWriterFlow.
     */
    public final NitfWriterFlow outputStream(final Supplier<OutputStream> outputStreamSupplier) {
        if (outputStreamSupplier != null) {
            this.streamSupplier = outputStreamSupplier;
        }

        return this;
    }

    /**
     * Writes the NITF to the current OutputStream.  If either outputStream() or file() hasn't
     * been called, no operation will be performed.
     *
     * @param dataSource the DataSource that represents the state of the NITF.
     * @return this NitfWriterFlow.
     */
    public final NitfWriterFlow write(final DataSource dataSource) {
        if (this.streamSupplier != null) {
            try (OutputStream outputStream = streamSupplier.get()) {
                NitfOutputStreamWriter nitfWriter = new NitfOutputStreamWriter(dataSource,
                        outputStream);
                nitfWriter.write();
            } catch (IOException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }

        return this;
    }
}

@@ -1143,268 +1143,9 @@
 eam.
-  Expected usage is that either%0A * outputStream() or file() will be called, not both. Calling them both will have the same effect%0A * as calling only the last one.  Calling write() before outputStream() or file() will result in%0A * no operation being performed.
 %0A
+
  */%0A
@@ -1436,48 +1436,8 @@
 imes
-, or calling file() after outputStream()
  wil
@@ -1904,17 +1904,23 @@
 tStream.
- 
+%0A     *
  If eith
@@ -1941,31 +1941,14 @@
 m() 
-or file() hasn't%0A     *
+hasn't
  bee

Update NitfWriterFlow.java