Class TextBannerFormatter


public final class TextBannerFormatter extends ExtFormatter.Delegating
A formatter which prints a text banner ahead of the normal formatter header. The text banner is acquired from a Supplier which is passed in to the constructor. Several utility methods are also present which allow easy creation of Supplier instances.
  • Constructor Details

    • TextBannerFormatter

      public TextBannerFormatter(Supplier<String> bannerSupplier, ExtFormatter delegate)
      Construct a new instance.
      Parameters:
      bannerSupplier - the supplier for the banner (must not be null)
      delegate - the delegate formatter (must not be null)
  • Method Details

    • getHead

      public String getHead(Handler h)
      Overrides:
      getHead in class ExtFormatter.Delegating
    • getEmptySupplier

      public static Supplier<String> getEmptySupplier()
      Get the empty supplier which always returns an empty string.
      Returns:
      the empty supplier (not null)
    • createStringSupplier

      public static Supplier<String> createStringSupplier(String string)
      Create a supplier which always returns the given string.
      Parameters:
      string - the string (must not be null)
      Returns:
      a supplier which returns the given string (not null)
    • createFileSupplier

      public static Supplier<String> createFileSupplier(Path path, Supplier<String> fallback)
      Create a supplier which loads the banner from the given file path, falling back to the given fallback supplier on error.
      Parameters:
      path - the path to load from (must not be null)
      fallback - the fallback supplier (must not be null)
      Returns:
      the supplier (not null)
    • createUrlSupplier

      public static Supplier<String> createUrlSupplier(URL url, Supplier<String> fallback)
      Create a supplier which loads the banner from the given URL, falling back to the given fallback supplier on error.
      Parameters:
      url - the URL to load from (must not be null)
      fallback - the fallback supplier (must not be null)
      Returns:
      the supplier (not null)
    • createResourceSupplier

      public static Supplier<String> createResourceSupplier(String resource, ClassLoader classLoader, Supplier<String> fallback)
      Create a supplier which loads the banner from a resource in the given class loader, falling back to the given fallback supplier on error.
      Parameters:
      resource - the resource name (must not be null)
      classLoader - the class loader to load from (must not be null)
      fallback - the fallback supplier (must not be null)
      Returns:
      the supplier (not null)
    • createResourceSupplier

      public static Supplier<String> createResourceSupplier(String resource, Supplier<String> fallback)
      Create a supplier which loads the banner from a resource in the caller's class loader, falling back to the given fallback supplier on error.
      Parameters:
      resource - the resource name (must not be null)
      fallback - the fallback supplier (must not be null)
      Returns:
      the supplier (not null)