Interface Target

All Known Implementing Classes:
ByteArrayTarget, FileTarget, OutputStreamTarget

public interface Target
Abstracts away access to an on-demand OutputStream over a given resource. Most implementations are able to provide repeated access to the underlying resource. However, not all resources can be reused and multiple calls to getOutputStream() will fail if isReusable() returns false.
Author:
jbanes
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an OutputStream over the underlying resource
    default boolean
    Returns true if the target is reusable.
    default boolean
    Returns true if the OutputStream has already been accessed and another attempt to access getOutputStream() will fail.
    default void
    write(byte[] data)
    Convenience method for writing data to a file.
    default void
    Convenience method for writing string data to a file in UTF-8 format.
    default void
    writeString(String data, String encoding)
    Convenience method for writing string data to a file.
  • Method Details

    • getOutputStream

      OutputStream getOutputStream()
      Returns an OutputStream over the underlying resource
      Returns:
      an OutputStream
    • isReusable

      default boolean isReusable()
      Returns true if the target is reusable. The default implementation returns true, so this must be overridden if your implementation is not reusable.
      Returns:
      true
    • isUsed

      default boolean isUsed()
      Returns true if the OutputStream has already been accessed and another attempt to access getOutputStream() will fail. The default implementation returns false, so this must be overridden if your implementation is not reusable.
      Returns:
      false
    • writeString

      default void writeString(String data)
      Convenience method for writing string data to a file in UTF-8 format. This is useful for quickly serializing in-memory data to a file, typically generated information that is of use to a user.
      Parameters:
      data - the string to write
    • writeString

      default void writeString(String data, String encoding)
      Convenience method for writing string data to a file. This is useful for quickly serializing in-memory data to a file, typically generated information that is of use to a user.
      Parameters:
      data - the string to write
      encoding - the desired character encoding
    • write

      default void write(byte[] data)
      Convenience method for writing data to a file. This is useful for quickly serializing in-memory data to a file, typically generated information that is of use to a user.
      Parameters:
      data - a byte array of the data to write