Class FileInfo

java.lang.Object
org.opentest4j.FileInfo
All Implemented Interfaces:
Serializable

public class FileInfo extends Object implements Serializable
FileInfo is a pair of a file path and the contents of the file.

Its main use case is for actual and expected values in AssertionFailedError.

The semantics of the path can be defined by the users of this class.

Since:
1.3
Author:
Marc Philipp, Reinhold Degenfellner
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileInfo(String path, byte[] contents)
    Constructs a FileInfo with a path to a file and the contents of the file.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Determines if the supplied object is an instance of FileInfo with the same path and contents as this FileInfo.
    byte[]
    Returns the contents of the file.
    Returns the contents of the file as a String.
    Returns the path to the file.
    int
    Generates a unique hash code for this FileInfo based on its path.
    Generates a string representation of this FileInfo based on the path and contents.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FileInfo

      public FileInfo(String path, byte[] contents)
      Constructs a FileInfo with a path to a file and the contents of the file.

      Be cautious with large files (limiting the size may be a good idea).

      The supplied byte array is not copied to avoid unnecessary memory allocations. However, callers of this constructors should not modify the byte array after calling this constructor. This behavior may change in a future release without prior notice.

      Parameters:
      path - the path to the file; must not be null
      contents - the contents of the file; must not be null;
  • Method Details

    • getPath

      public String getPath()
      Returns the path to the file.
      Returns:
      the path to the file; never null
    • getContents

      public byte[] getContents()
      Returns the contents of the file.

      This method does currently not return a defensive copy of the contained byte array to avoid unnecessary memory allocations. However, callers of this method should not modify the returned byte array. This behavior may change in a future release without prior notice.

      Returns:
      the contents of the file; never null
    • getContentsAsString

      public String getContentsAsString(Charset charset)
      Returns the contents of the file as a String.
      Returns:
      the contents of the file as a String; never null
    • equals

      public boolean equals(Object obj)
      Determines if the supplied object is an instance of FileInfo with the same path and contents as this FileInfo.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Generates a unique hash code for this FileInfo based on its path.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Generates a string representation of this FileInfo based on the path and contents.
      Overrides:
      toString in class Object