Package de.xima.fc.common.data.file
Class DefaultSerializableFile
- java.lang.Object
-
- de.xima.fc.common.data.file.DefaultSerializableFile
-
- All Implemented Interfaces:
ISerializableFile
,Serializable
public final class DefaultSerializableFile extends Object implements ISerializableFile
Default implementation ofISerializableFile
with several static factory methods for creating instances.- Since:
- 8.2.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
contentType()
Gets the content type (mime type) of the file.ISerializableInputStreamSupplier
data()
Gets the binary data of the file.static ISerializableFile
emptySerializableFile(String fileName, String contentType)
Creates an empty serializable file with the given file name and content type.String
fileName()
Gets the name of the file.long
fileSize()
Gets the size of the file in bytes.static ISerializableFile
serializableFile(String fileName, String contentType, byte[] data)
Creates a serializable file with the given file name, content type and data.static ISerializableFile
serializableFile(String fileName, String contentType, long fileSize, ISerializableInputStreamSupplier data)
Creates a serializable file with the given file name, content type and data.static ISerializableFile
serializableFile(String fileName, String contentType, File data)
Creates a serializable file with the given file name, content type and data.static ISerializableFile
serializableFile(String fileName, String contentType, InputStream data)
Creates a serializable file with the given file name, content type and data.static ISerializableFile
serializableFile(String fileName, String contentType, String textData, Charset charset)
Creates a serializable file with the given file name, content type and data.static ISerializableFile
serializableFile(String fileName, String contentType, Path data)
Creates a serializable file with the given file name, content type and data.
-
-
-
Method Detail
-
contentType
public String contentType()
Description copied from interface:ISerializableFile
Gets the content type (mime type) of the file.- Specified by:
contentType
in interfaceISerializableFile
- Returns:
- The content type of the file.
-
data
public ISerializableInputStreamSupplier data()
Description copied from interface:ISerializableFile
Gets the binary data of the file. Must not be null and contain at least one byte.- Specified by:
data
in interfaceISerializableFile
- Returns:
- The binary data of the file.
-
fileName
public String fileName()
Description copied from interface:ISerializableFile
Gets the name of the file. Must not be blank.- Specified by:
fileName
in interfaceISerializableFile
- Returns:
- The name of the file.
-
fileSize
public long fileSize()
Description copied from interface:ISerializableFile
Gets the size of the file in bytes.- Specified by:
fileSize
in interfaceISerializableFile
- Returns:
- The size of the file in bytes.
-
emptySerializableFile
public static ISerializableFile emptySerializableFile(String fileName, String contentType)
Creates an empty serializable file with the given file name and content type.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.- Returns:
- An empty serializable file with the given file name and content type.
-
serializableFile
public static ISerializableFile serializableFile(String fileName, String contentType, File data)
Creates a serializable file with the given file name, content type and data.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.data
- The data of the file.- Returns:
- A serializable file with the given file name, content type and data.
-
serializableFile
public static ISerializableFile serializableFile(String fileName, String contentType, Path data) throws IOException
Creates a serializable file with the given file name, content type and data.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.data
- The data of the file.- Returns:
- A serializable file with the given file name, content type and data.
- Throws:
IOException
-
serializableFile
public static ISerializableFile serializableFile(String fileName, String contentType, byte[] data)
Creates a serializable file with the given file name, content type and data.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.data
- The data of the file.- Returns:
- A serializable file with the given file name, content type and data.
-
serializableFile
public static ISerializableFile serializableFile(String fileName, String contentType, String textData, Charset charset)
Creates a serializable file with the given file name, content type and data.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.textData
- The text data of the file.charset
- The charset of the text data.- Returns:
- A serializable file with the given file name, content type and data.
-
serializableFile
public static ISerializableFile serializableFile(String fileName, String contentType, long fileSize, ISerializableInputStreamSupplier data)
Creates a serializable file with the given file name, content type and data.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.fileSize
- The size of the file in bytes.data
- The data of the file.- Returns:
- A serializable file with the given file name, content type and data.
-
serializableFile
public static ISerializableFile serializableFile(String fileName, String contentType, InputStream data) throws IOException
Creates a serializable file with the given file name, content type and data. Note that since the instance must be serializable, the data from the input stream will be read into memory.- Parameters:
fileName
- The name of the file.contentType
- The content type of the file.data
- The data of the file.- Returns:
- A serializable file with the given file name, content type and data.
- Throws:
IOException
-
-