Class CharsetHelper.InputStreamAndCharset

java.lang.Object
com.helger.base.charset.CharsetHelper.InputStreamAndCharset
All Implemented Interfaces:
IHasInputStream
Enclosing class:
CharsetHelper

public static final class CharsetHelper.InputStreamAndCharset extends Object implements IHasInputStream
A wrapper that has an InputStream, an optional Unicode BOM as EUnicodeBOM and an optional Charset.
Author:
Philip Helger
  • Constructor Details

    • InputStreamAndCharset

      public InputStreamAndCharset(@NonNull InputStream aIS, @Nullable EUnicodeBOM eBOM, @Nullable Charset aCharset)
      Constructor.
      Parameters:
      aIS - The input stream. May not be null.
      eBOM - The detected Unicode BOM. May be null.
      aCharset - The detected charset. May be null.
  • Method Details

    • getInputStream

      public @NonNull InputStream getInputStream()
      Description copied from interface: IHasInputStream
      Get the input stream to read from the object. Each time this method is called, a new InputStream needs to be created.
      Specified by:
      getInputStream in interface IHasInputStream
      Returns:
      The input stream. Never null.
    • isReadMultiple

      public boolean isReadMultiple()
      Description copied from interface: IHasInputStream
      Check if the InputStream from IHasInputStream.getInputStream() and IHasInputStream.getBufferedInputStream() can be acquired more than once.
      Specified by:
      isReadMultiple in interface IHasInputStream
      Returns:
      false because the input stream can only be read once.
    • getBOM

      public @Nullable EUnicodeBOM getBOM()
      Returns:
      The detected Unicode BOM. May be null if none was found.
    • hasBOM

      public boolean hasBOM()
      Returns:
      true if a Unicode BOM was detected, false otherwise.
    • getCharset

      public @Nullable Charset getCharset()
      Returns:
      The detected charset from the BOM. May be null.
    • hasCharset

      public boolean hasCharset()
      Returns:
      true if a charset was detected from the BOM, false otherwise.
    • getCharset

      public @Nullable Charset getCharset(@Nullable Charset aFallbackCharset)
      Get the detected charset or the provided fallback.
      Parameters:
      aFallbackCharset - The fallback charset to use. May be null.
      Returns:
      The detected charset or the fallback charset.