Package com.helger.io.stream
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 TypeMethodDescriptionstatic @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 voidreadStreamLines(@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 voidreadStreamLines(@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 voidreadStreamLines(@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
-
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 benull.aCharset- The character set to use. May not benull.- Returns:
nullif the resolved input stream isnull, 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 benull.aCharset- The character set to use. May not benull.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 inCGlobal.ILLEGAL_UINTto indicate that all lines should be read. If the number passed here exceeds the number of lines in the file, nothing happens.- Returns:
nullif the resolved input stream isnull, 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 benull.aCharset- The character set to use. May not benull.- Returns:
nullif the input stream isnull, 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 benull.aCharset- The character set to use. May not benull.aTargetList- The list to be filled with the lines. May not benull.
-
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 benull.aCharset- The character set to use. May not benull.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 inCGlobal.ILLEGAL_UINTto indicate that all lines should be read. If the number passed here exceeds the number of lines in the file, nothing happens.- Returns:
nullif the input stream isnull, 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 benull.aCharset- The character set to use. May not benull.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 benull.aCharset- The character set to use. May not benull.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 inCGlobal.ILLEGAL_UINTto 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!
-