Class EmbeddedFile
java.lang.Object
org.sentrysoftware.metricshub.engine.connector.model.common.EmbeddedFile
- All Implemented Interfaces:
Serializable
Represents an embedded file within a connector.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of the current embedded file.Gets a string containing the embedded file reference.static EmbeddedFilefromString(@NonNull String value) Provides a convenient way to create an embedded file from a string without specifying a character set, assuming UTF-8.static EmbeddedFilefromString(@NonNull String value, @NonNull Charset charset) Creates anEmbeddedFilefrom a provided string, encoding the content using the specifiedCharset.Retrieves the filename without its extension.Provides a convenient way to convert content to a string when UTF-8 encoding is assumed.getContentAsString(@NonNull Charset charset) Converts the byte array content of this embedded file into a string using the specifiedCharset.Retrieves the file extension from the filename of this object.voidupdate(UnaryOperator<String> updater) Applies a specified transformation to the content of the embedded file, if content is present.
-
Constructor Details
-
EmbeddedFile
public EmbeddedFile()
-
-
Method Details
-
copy
Creates a copy of the current embedded file.- Returns:
- A new instance of
EmbeddedFilewith the same content, filename, and reference.
-
description
Gets a string containing the embedded file reference.- Returns:
- A string representing the reference to the embedded file.
-
update
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 aString, transformed by the providedUnaryOperator, 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- AUnaryOperator<String>that takes the current content as aStringand returns the modified content. The operation must not returnnull; 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 anEmbeddedFilefrom a provided string, encoding the content using the specifiedCharset.- Parameters:
value- The string content to be converted into an embedded file.charset- TheCharsetused to encode the string into bytes.- Returns:
- An
EmbeddedFilewith the provided string content encoded into bytes.
-
fromString
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
EmbeddedFilewith the content encoded as UTF-8 bytes.
-
getContentAsString
Converts the byte array content of this embedded file into a string using the specifiedCharset.- Parameters:
charset- TheCharsetto be used for decoding the byte content.- Returns:
- The string representation of the embedded file's content.
-
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
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
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.
-