java.lang.Object
org.sentrysoftware.metricshub.engine.connector.model.common.EmbeddedFile
All Implemented Interfaces:
Serializable

public class EmbeddedFile extends Object implements Serializable
Represents an embedded file within a connector.
See Also:
  • Constructor Details

    • EmbeddedFile

      public EmbeddedFile()
  • Method Details

    • copy

      public EmbeddedFile copy()
      Creates a copy of the current embedded file.
      Returns:
      A new instance of EmbeddedFile with the same content, filename, and reference.
    • description

      public String description()
      Gets a string containing the embedded file reference.
      Returns:
      A string representing the reference to the embedded file.
    • update

      public void update(UnaryOperator<String> updater)
      Applies a specified transformation to the content of the embedded file, if content is present. The file content is initially decoded using UTF-8 charset into a String, transformed by the provided UnaryOperator, and then re-encoded back into bytes using UTF-8. Note: This method assumes that the content is text-based and can be correctly encoded and decoded using UTF-8. Non-text content or content that does not conform to UTF-8 encoding may result in data corruption or loss.
      Parameters:
      updater - A UnaryOperator<String> that takes the current content as a String and returns the modified content. The operation must not return null; if no modification is needed, the original string should be returned.
    • fromString

      public static EmbeddedFile fromString(@NonNull @NonNull String value, @NonNull @NonNull Charset charset)
      Creates an EmbeddedFile from a provided string, encoding the content using the specified Charset.
      Parameters:
      value - The string content to be converted into an embedded file.
      charset - The Charset used to encode the string into bytes.
      Returns:
      An EmbeddedFile with the provided string content encoded into bytes.
    • fromString

      public static EmbeddedFile fromString(@NonNull @NonNull String value)
      Provides a convenient way to create an embedded file from a string without specifying a character set, assuming UTF-8.
      Parameters:
      value - The string content to be converted into an embedded file.
      Returns:
      An EmbeddedFile with the content encoded as UTF-8 bytes.
    • getContentAsString

      public String getContentAsString(@NonNull @NonNull Charset charset)
      Converts the byte array content of this embedded file into a string using the specified Charset.
      Parameters:
      charset - The Charset to be used for decoding the byte content.
      Returns:
      The string representation of the embedded file's content.
    • getContentAsString

      public String getContentAsString()
      Provides a convenient way to convert content to a string when UTF-8 encoding is assumed.
      Returns:
      The string representation of the embedded file's content, decoded using UTF-8.
    • getFileExtension

      public String getFileExtension()
      Retrieves the file extension from the filename of this object. If the filename is not available an empty string is returned.
      Returns:
      The file extension as a string. Returns an empty string if the filename is null or does not have an extension.
    • getBaseName

      public String getBaseName()
      Retrieves the filename without its extension. If the filename is not available an empty string is returned.
      Returns:
      The base name of the file as a string. Returns an empty string if the filename is null.