Class ConcatenationInputStream

java.lang.Object
java.io.InputStream
com.saperion.common.io.ConcatenationInputStream
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable

public class ConcatenationInputStream extends InputStream implements Serializable
Concatenates several input streams to another input stream so that if one reads the resulting stream it is the same as reading the streams one after another. A ConcatenationInputStream is serializable if and only if all the streams concatenated are serializable.
Author:
jschwarz
See Also:
  • Constructor Details

    • ConcatenationInputStream

      public ConcatenationInputStream(List<? extends InputStream> streams)
      Creates a new ConcatenationInputStream that concatenates the given streams
      Parameters:
      streams - the streams to concatenate
  • Method Details

    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class InputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • create

      public static InputStream create(InputStream... streams)
      Creates a new InputStream that concatenates the given streams.

      If streams is null or does not contain any elements an EmptyInputStream is created. If streams contains one and only one element this element is returned. Otherwise a ConcatenationInputStream is returned.

      Parameters:
      streams - the streams to concatenate
      Returns:
      a new InputStream that concatenates the given streams
    • create

      public static InputStream create(List<? extends InputStream> streams)
      Creates a new InputStream that concatenates the given streams.

      If streams is null or does not contain any elements an EmptyInputStream is created. If streams contains one and only one element this element is returned. Otherwise a ConcatenationInputStream is returned.

      Parameters:
      streams - the streams to concatenate
      Returns:
      a new InputStream that concatenates the given streams