/**
 * Copyright (C) 2016-2018 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.helger.mail.datasource;

import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataSource;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.UnsupportedOperation;
import com.helger.commons.mime.IMimeType;
import com.helger.commons.string.ToStringGenerator;

/**
 * A special {@link DataSource} implementation based on data from
 * {@link InputStream}.
 *
 * @author Philip Helger
 */
@NotThreadSafe
public class InputStreamDataSource implements IExtendedDataSource
{
  private final InputStream m_aIS;
  private int m_nISAcquired = 0;
  private final String m_sName;
  private final String m_sContentType;

  public InputStreamDataSource (@Nonnull final InputStream aIS, @Nonnull final String sName)
  {
    this (aIS, sName, (String) null);
  }

  public InputStreamDataSource (@Nonnull final InputStream aIS,
                                @Nonnull final String sName,
                                @Nullable final IMimeType aContentType)
  {
    this (aIS, sName, aContentType == null ? null : aContentType.getAsString ());
  }

  public InputStreamDataSource (@Nonnull final InputStream aIS,
                                @Nonnull final String sName,
                                @Nullable final String sContentType)
  {
    m_aIS = ValueEnforcer.notNull (aIS, "InputStream");
    m_sName = ValueEnforcer.notNull (sName, "Name");
    m_sContentType = sContentType != null ? sContentType : DEFAULT_CONTENT_TYPE.getAsString ();
  }

  @Nonnull
  public InputStream getInputStream ()
  {
    m_nISAcquired++;
    if (m_nISAcquired > 1)
      throw new IllegalStateException ("The input stream was already acquired " + (m_nISAcquired - 1) + " times!");
    return m_aIS;
  }

  @UnsupportedOperation
  public OutputStream getOutputStream ()
  {
    throw new UnsupportedOperationException ("Read-only!");
  }

  @Nonnull
  public String getContentType ()
  {
    return m_sContentType;
  }

  @Nonnull
  public String getName ()
  {
    return m_sName;
  }

  @Override
  public String toString ()
  {
    return new ToStringGenerator (this).append ("IS", m_aIS)
                                       .append ("ISAcquired", m_nISAcquired)
                                       .append ("Name", m_sName)
                                       .append ("ContentType", m_sContentType)
                                       .getToString ();
  }
}

@@ -1440,16 +1440,71 @@
 entType;
+%0A  private boolean m_bAllowMultipeGetInputStream=false;
 %0A%0A  publ
@@ -1917,32 +1917,419 @@
 tring ());%0A  %7D%0A%0A
+  public InputStreamDataSource (@Nonnull final InputStream aIS,%0A                                @Nonnull final String sName,%0A                                @Nullable final String sContentType,%0A                                final boolean aAllowMultipleGetInputStream)%0A  %7B%0A    this (aIS, sName, sContentType);%0A    this.m_bAllowMultipeGetInputStream = aAllowMultipleGetInputStream;%0A  %7D%0A%0A
   public InputSt
@@ -2799,16 +2799,16 @@
 ++;%0A
-
     if (
 m_nI
@@ -2803,16 +2803,52 @@
     if (
+(!m_bAllowMultipeGetInputStream) && 
 m_nISAcq

Add option to allow multiple getInputStream on InputStreamDataSource