Class StreamHelperExt

java.lang.Object
com.helger.base.io.stream.StreamHelper
com.helger.io.stream.StreamHelperExt

@Immutable public final class StreamHelperExt extends com.helger.base.io.stream.StreamHelper
Some very basic IO stream utility stuff. All input stream (=reading) related stuff is quite null aware, where on writing an output stream may never be null.
Author:
Philip Helger
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.helger.base.io.stream.StreamHelper

    com.helger.base.io.stream.StreamHelper.CopyByteStreamBuilder, com.helger.base.io.stream.StreamHelper.CopyCharStreamBuilder
  • Field Summary

    Fields inherited from class com.helger.base.io.stream.StreamHelper

    DEFAULT_BUFSIZE, END_OF_STRING_MARKER, MAX_SAFE_UTF_BYTES
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable com.helger.collection.commons.ICommonsList<String>
    readStreamLines(@Nullable com.helger.base.io.iface.IHasInputStream aISP, @NonNull Charset aCharset)
    Get the content of the passed Spring resource as one big string in the passed character set.
    static @Nullable com.helger.collection.commons.ICommonsList<String>
    readStreamLines(@Nullable com.helger.base.io.iface.IHasInputStream aISP, @NonNull Charset aCharset, int nLinesToSkip, int nLinesToRead)
    Get the content of the passed Spring resource as one big string in the passed character set.
    static @Nullable com.helger.collection.commons.ICommonsList<String>
    readStreamLines(@Nullable InputStream aIS, @NonNull @Nonempty Charset aCharset)
    Get the content of the passed stream as a list of lines in the passed character set.
    static void
    readStreamLines(@Nullable InputStream aIS, @NonNull @Nonempty Charset aCharset, int nLinesToSkip, int nLinesToRead, @NonNull Consumer<? super String> aLineCallback)
    Read the content of the passed stream line by line and invoking a callback on all matching lines.
    static void
    readStreamLines(@Nullable InputStream aIS, @NonNull @Nonempty Charset aCharset, @NonNull Consumer<? super String> aLineCallback)
    Read the complete content of the passed stream and pass each line separately to the passed callback.
    static @Nullable com.helger.collection.commons.ICommonsList<String>
    readStreamLines(@Nullable InputStream aIS, @NonNull Charset aCharset, int nLinesToSkip, int nLinesToRead)
    Get the content of the passed stream as a list of lines in the passed character set.
    static void
    readStreamLines(@Nullable InputStream aIS, @NonNull Charset aCharset, @NonNull List<String> aTargetList)
    Get the content of the passed stream as a list of lines in the passed character set.

    Methods inherited from class com.helger.base.io.stream.StreamHelper

    checkForInvalidFilterInputStream, close, closeWithoutFlush, copyByteStream, copyCharStream, copyInputStreamToOutputStream, copyInputStreamToOutputStreamAndCloseOS, copyReaderToWriter, copyReaderToWriterAndCloseWriter, createDefaultCopyBufferBytes, createDefaultCopyBufferChars, createReader, createReader, createReader, createWriter, flush, getAllBytes, getAllBytes, getAllBytesAsString, getAllBytesAsString, getAllCharacters, getAllCharactersAsString, getAvailable, getBuffered, getBuffered, getBuffered, getBuffered, getCopy, getCopy, getCopyWithLimit, getCopyWithLimit, internalGetPropagatableException, isBuffered, isBuffered, isBuffered, isBuffered, isKnownEOFException, isKnownEOFException, readFully, readFully, readSafeUTF, readUntilEOF, readUntilEOF, readUntilEOF, readUntilEOF, skipFully, writeSafeUTF, writeStream, writeStream, writeStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • readStreamLines

      @ReturnsMutableCopy public static @Nullable com.helger.collection.commons.ICommonsList<String> readStreamLines(@Nullable com.helger.base.io.iface.IHasInputStream aISP, @NonNull Charset aCharset)
      Get the content of the passed Spring resource as one big string in the passed character set.
      Parameters:
      aISP - The resource to read. May not be null.
      aCharset - The character set to use. May not be null.
      Returns:
      null if the resolved input stream is null , the content otherwise.
    • readStreamLines

      @ReturnsMutableCopy public static @Nullable com.helger.collection.commons.ICommonsList<String> readStreamLines(@Nullable com.helger.base.io.iface.IHasInputStream aISP, @NonNull Charset aCharset, @Nonnegative int nLinesToSkip, @CheckForSigned int nLinesToRead)
      Get the content of the passed Spring resource as one big string in the passed character set.
      Parameters:
      aISP - The resource to read. May be null.
      aCharset - The character set to use. May not be null.
      nLinesToSkip - The 0-based index of the first line to read. Pass in 0 to indicate to read everything.
      nLinesToRead - The number of lines to read. Pass in CGlobal.ILLEGAL_UINT to indicate that all lines should be read. If the number passed here exceeds the number of lines in the file, nothing happens.
      Returns:
      null if the resolved input stream is null , the content otherwise.
    • readStreamLines

      @ReturnsMutableCopy public static @Nullable com.helger.collection.commons.ICommonsList<String> readStreamLines(@WillClose @Nullable InputStream aIS, @Nonempty @NonNull @Nonempty Charset aCharset)
      Get the content of the passed stream as a list of lines in the passed character set.
      Parameters:
      aIS - The input stream to read from. May be null.
      aCharset - The character set to use. May not be null.
      Returns:
      null if the input stream is null, the content lines otherwise.
    • readStreamLines

      public static void readStreamLines(@WillClose @Nullable InputStream aIS, @NonNull Charset aCharset, @NonNull List<String> aTargetList)
      Get the content of the passed stream as a list of lines in the passed character set.
      Parameters:
      aIS - The input stream to read from. May be null.
      aCharset - The character set to use. May not be null.
      aTargetList - The list to be filled with the lines. May not be null.
    • readStreamLines

      @ReturnsMutableCopy public static @Nullable com.helger.collection.commons.ICommonsList<String> readStreamLines(@WillClose @Nullable InputStream aIS, @NonNull Charset aCharset, @Nonnegative int nLinesToSkip, @CheckForSigned int nLinesToRead)
      Get the content of the passed stream as a list of lines in the passed character set.
      Parameters:
      aIS - The input stream to read from. May be null.
      aCharset - The character set to use. May not be null.
      nLinesToSkip - The 0-based index of the first line to read. Pass in 0 to indicate to read everything.
      nLinesToRead - The number of lines to read. Pass in CGlobal.ILLEGAL_UINT to indicate that all lines should be read. If the number passed here exceeds the number of lines in the file, nothing happens.
      Returns:
      null if the input stream is null, the content lines otherwise.
    • readStreamLines

      public static void readStreamLines(@WillClose @Nullable InputStream aIS, @Nonempty @NonNull @Nonempty Charset aCharset, @NonNull Consumer<? super String> aLineCallback)
      Read the complete content of the passed stream and pass each line separately to the passed callback.
      Parameters:
      aIS - The input stream to read from. May be null.
      aCharset - The character set to use. May not be null.
      aLineCallback - The callback that is invoked for all read lines. Each passed line does NOT contain the line delimiter!
    • readStreamLines

      public static void readStreamLines(@WillClose @Nullable InputStream aIS, @Nonempty @NonNull @Nonempty Charset aCharset, @Nonnegative int nLinesToSkip, int nLinesToRead, @NonNull Consumer<? super String> aLineCallback)
      Read the content of the passed stream line by line and invoking a callback on all matching lines.
      Parameters:
      aIS - The input stream to read from. May be null.
      aCharset - The character set to use. May not be null.
      nLinesToSkip - The 0-based index of the first line to read. Pass in 0 to indicate to read everything.
      nLinesToRead - The number of lines to read. Pass in CGlobal.ILLEGAL_UINT to indicate that all lines should be read. If the number passed here exceeds the number of lines in the file, nothing happens.
      aLineCallback - The callback that is invoked for all read lines. Each passed line does NOT contain the line delimiter! Note: it is not invoked for skipped lines!