Class StreamIteratorUtils

java.lang.Object
io.clonecloudstore.common.standard.stream.StreamIteratorUtils

public class StreamIteratorUtils extends Object
Utility class to help to create an InputStream of serialized objects from a Stream of Objects and reverse. Note that DTO class must have an empty constructor or being a record.
  • Constructor Details Link icon

    • StreamIteratorUtils Link icon

      public StreamIteratorUtils()
  • Method Details Link icon

    • getInputStreamFromStream Link icon

      public static InputStream getInputStreamFromStream(Stream<?> stream, Class<?> forClass) throws IOException
      Parameters:
      stream - The Stream to transform to InputStream of Json serialized Objects
      forClass - the object Class
      Returns:
      the InputStream usable in REST API
      Throws:
      IOException - if an issue occurs
    • getInputStreamFromStream Link icon

      public static InputStream getInputStreamFromStream(Stream<?> stream, StreamIteratorUtils.Transform transform, Class<?> forClass) throws IOException
      Parameters:
      stream - The Stream to transform to InputStream of Json serialized Objects
      transform - function to convert source Stream object to another one
      forClass - the object Class
      Returns:
      the InputStream usable in REST API
      Throws:
      IOException - if an issue occurs
    • getInputStreamFromIterator Link icon

      public static InputStream getInputStreamFromIterator(Iterator<?> iterator, Class<?> forClass) throws IOException
      Parameters:
      iterator - The Iterator to transform to InputStream of Json serialized Objects
      forClass - the object Class
      Returns:
      the InputStream usable in REST API
      Throws:
      IOException - if an issue occurs
    • getInputStreamFromIterator Link icon

      public static InputStream getInputStreamFromIterator(Iterator<?> iterator, StreamIteratorUtils.Transform transform, Class<?> forClass) throws IOException
      Parameters:
      iterator - The Iterator to transform to InputStream of Json serialized Objects
      transform - function to convert source Stream object to another one
      forClass - the object Class
      Returns:
      the InputStream usable in REST API
      Throws:
      IOException - if an issue occurs
    • getStreamFromInputStream Link icon

      public static <E> Stream<E> getStreamFromInputStream(InputStream inputStream, Class<E> forClass) throws CcsWithStatusException
      Parameters:
      inputStream - the InputStream containing Json Objects
      forClass - the object Class
      Returns:
      The Stream of deserialized Objects
      Throws:
      CcsWithStatusException - if an issue occurs during streaming
    • getIteratorFromInputStream Link icon

      public static <E> ClosingIterator<E> getIteratorFromInputStream(InputStream inputStream, Class<E> forClass)
      Parameters:
      inputStream - the InputStream containing Json Objects
      forClass - the object Class
      Returns:
      The Stream of deserialized Objects
      Throws:
      CcsInvalidArgumentRuntimeException - if an issue occurs during iterating
    • getListFromIterator Link icon

      public static <E> List<E> getListFromIterator(Iterator<E> iterator)
      Transform Iterator to List (all in memory)
    • getStreamFromIterator Link icon

      public static <E> Stream<E> getStreamFromIterator(Iterator<E> iterator)
      Transform Iterator to Stream