Class PromptConfigFile
- java.lang.Object
-
- de.xima.fc.prompt.service.support.PromptConfigFile
-
- All Implemented Interfaces:
Serializable
public final class PromptConfigFile extends Object implements Serializable
View model for a single file, intended to be used as part of thedeserialized prompt connection configurationordeserialized prompt query configuration.- Since:
- 8.5.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PromptConfigFile()Creates a new empty file with 0 bytes.PromptConfigFile(IPromptBinaryData data)Creates a new file preloaded with the content of the given binary data.PromptConfigFile(String fileName, String mimeType, Path content)Creates a new file preloaded with the content of the file at the given path.PromptConfigFile(String fileName, String mimeType, Instant lastModified, byte[] data)Creates a new file with the given name, MIME type, and binary data.PromptConfigFile(String fileName, String mimeType, Instant lastModified, int fileSize, ISerializableInputStreamSupplier data)Creates a new file with the given name, MIME type, last modified date, and binary data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStreamgetFileContent()Opens an input stream to the file content.StringgetFileName()Gets the name of the file, e.g.intgetFileSize()Gets the size of the file in bytes.InstantgetLastModified()Gets the time the file was last modified.StringgetMimeType()Gets the MIME type of the file, e.g.voidsetFileContent(byte[] data)Sets the file content to a byte array.voidsetFileContent(IPromptBinaryData data)Sets the file content to the given binary data.voidsetFileContent(Path path)Sets the file content to a file at the given path.voidsetFileName(String fileName)Sets the name of the file, e.g.voidsetFileSize(int fileSize)Sets the size of the file in bytes.voidsetLastModified(Instant lastModified)Sets the time the file was last modified.voidsetMimeType(String mimeType)Sets the MIME type of the file, e.g.
-
-
-
Constructor Detail
-
PromptConfigFile
public PromptConfigFile()
Creates a new empty file with 0 bytes.
-
PromptConfigFile
public PromptConfigFile(String fileName, String mimeType, Instant lastModified, byte[] data)
Creates a new file with the given name, MIME type, and binary data.- Parameters:
fileName- The name of the file, e.g. "image.png". If empty, defaults to "data".mimeType- The MIME type of the file, e.g. "image/png". If empty, defaults to "application/octet-stream".data- The binary data to preload. If null, the file will be empty with 0 bytes.
-
PromptConfigFile
public PromptConfigFile(String fileName, String mimeType, Instant lastModified, int fileSize, ISerializableInputStreamSupplier data)
Creates a new file with the given name, MIME type, last modified date, and binary data.- Parameters:
fileName- The name of the file, e.g. "image.png". If empty, defaults to "data".mimeType- The MIME type of the file, e.g. "image/png". If empty, defaults to "application/octet-stream".lastModified- The last modified timestamp of the file. If null, defaults to the current time.fileSize- The size of the file in bytes.data- The binary data to preload. If null, the file will be empty with 0 bytes.
-
PromptConfigFile
public PromptConfigFile(String fileName, String mimeType, Path content)
Creates a new file preloaded with the content of the file at the given path.- Parameters:
fileName- The name of the file. Defaults to the name of the givenPathwhen empty.mimeType- The MIME type of the file. Defaults to "application/octet-stream" when empty.content- The path to the file on the disk.
-
PromptConfigFile
public PromptConfigFile(IPromptBinaryData data)
Creates a new file preloaded with the content of the given binary data.- Parameters:
data- The binary data to preload
-
-
Method Detail
-
getFileContent
public InputStream getFileContent() throws IOException
Opens an input stream to the file content.- Returns:
- An input stream to the file content, or an empty input stream if no content is set.
- Throws:
IOException
-
setFileContent
public void setFileContent(Path path)
Sets the file content to a file at the given path.- Parameters:
path- The path to the file that contains the new content.
-
setFileContent
public void setFileContent(IPromptBinaryData data)
Sets the file content to the given binary data.- Parameters:
data- The binary data to set as the file content.
-
setFileContent
public void setFileContent(byte[] data)
Sets the file content to a byte array. Use with caution, as this will keep the entire byte array in memory.- Parameters:
data- The byte array to set as file content.
-
getFileName
public String getFileName()
Gets the name of the file, e.g. "image.png".- Returns:
- The name of the file.
-
setFileName
public void setFileName(String fileName)
Sets the name of the file, e.g. "image.png".- Parameters:
fileName- The name of the file.
-
getFileSize
public int getFileSize()
Gets the size of the file in bytes.- Returns:
- The size of the file.
-
setFileSize
public void setFileSize(int fileSize)
Sets the size of the file in bytes.- Parameters:
fileSize- The size of the file.
-
getLastModified
public Instant getLastModified()
Gets the time the file was last modified. For newly created files, this is the time of creation.- Returns:
- The last modified timestamp of the file.
-
setLastModified
public void setLastModified(Instant lastModified)
Sets the time the file was last modified. For newly created files, this is the time of creation.- Parameters:
lastModified- The last modified timestamp of the file.
-
getMimeType
public String getMimeType()
Gets the MIME type of the file, e.g. "image/png". When the content is plain text, should contain the encoding as well, e.g. "text/plain; charset=UTF-8". If no encoding is specified, the default is UTF-8. When no MIME type is set, the system may try to detect the type or default to "application/octet-stream".- Returns:
- The MIME type of the file.
-
setMimeType
public void setMimeType(String mimeType)
Sets the MIME type of the file, e.g. "image/png". When the content is plain text, should contain the encoding as well, e.g. "text/plain; charset=UTF-8". If no encoding is specified, the default is UTF-8. When no MIME type is set, the system may try to detect the type or default to "application/octet-stream".- Parameters:
mimeType- The MIME type of the file.
-
-