Class TempFileManager
java.lang.Object
org.eclnt.jsfserver.util.tempfile.TempFileManager
Little framework for storing any content (byte[]) in a temporary file system
and to provide a URL that points to this content.
Each content receives some internal id, which is then picked up within the URL that is created and which is processed by
The content is automatically removed from the temporary file system when the session is closed.
Each content receives some internal id, which is then picked up within the URL that is created and which is processed by
TempFileAccessServlet
.
The content is automatically removed from the temporary file system when the session is closed.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
clear
(javax.servlet.http.HttpSession session) Clear complete content of file manager for the current session.static String
findTempFileContentType
(String filePathOfSavedFile) Read the content type for a file that was written.static String
findTempFileContentType
(String sessionId, String path) Read the content type - if it was passed when callingsaveTempFile(String, String, byte[])
.static String
findTempFileContentType
(javax.servlet.http.HttpSession session, String path) Read the content type - if it was passed when callingsaveTempFile(String, String, byte[])
.static String
findTempFilePath
(String sessionId, String path) Finds the location of the temp file.static String
findTempFilePath
(javax.servlet.http.HttpSession session, String path) Finds the location of the temp file.static void
initialize
(javax.servlet.ServletContext servletContext) Internally called during start up of server.static void
initTempFileDirectory
(String directory) By default the servlet temp directory is used for storing the temporary files.static byte[]
readTempFile
(javax.servlet.http.HttpSession session, String path) Read the content of the temp file manager.static String
saveTempFile
(String fileName, byte[] content) static String
saveTempFile
(String fileName, String contentType, byte[] content) Extended version ofsaveTempFile(String, byte[])
, now also providing the possibility to also pass the content type as parameter.static String
saveTempFile
(String fileName, String contentType, byte[] content, String sessionId) Extended version ofsaveTempFile(String, byte[])
, now also providing the possibility to also pass the content type as parameter.static String
saveTempFileCrossSession
(String fileName, String contentType, byte[] content) Same assaveTempFile(String, String, byte[])
, but now saves the content in a way that it can be late on a accessed without enforcing the caller to be in the same session than the provider of the data.static String
-
Field Details
-
CROSS_SESSION_SESSIONID
- See Also:
-
-
Constructor Details
-
TempFileManager
public TempFileManager()
-
-
Method Details
-
initialize
public static void initialize(javax.servlet.ServletContext servletContext) Internally called during start up of server. -
initTempFileDirectory
By default the servlet temp directory is used for storing the temporary files. But: you may define some own directory as well. -
readTempFile
Read the content of the temp file manager.- Parameters:
session
-path
-- Returns:
-
findTempFileContentType
Read the content type - if it was passed when callingsaveTempFile(String, String, byte[])
. -
findTempFileContentType
Read the content type - if it was passed when callingsaveTempFile(String, String, byte[])
. -
findTempFileContentType
Read the content type for a file that was written. -
findTempFilePath
Finds the location of the temp file.- Parameters:
session
-path
-- Returns:
-
findTempFilePath
Finds the location of the temp file.- Parameters:
session
-path
-- Returns:
-
saveTempFile
- Parameters:
fileName
- File name of the document. This is the file name without directory. The temp file actually is stored in some directory with a UUID, so that each temp file resides in its own directory.content
- content- Returns:
- URL to access this content
-
saveTempFile
Extended version ofsaveTempFile(String, byte[])
, now also providing the possibility to also pass the content type as parameter.- Parameters:
contentType
- Content type of document. This is the one that is set as content type in the http-request that reads the temp file. If it is not set, then the content type will be derived from the extension of the file name.
-
saveTempFileCrossSession
Same assaveTempFile(String, String, byte[])
, but now saves the content in a way that it can be late on a accessed without enforcing the caller to be in the same session than the provider of the data. -
saveTempFile
public static String saveTempFile(String fileName, String contentType, byte[] content, String sessionId) Extended version ofsaveTempFile(String, byte[])
, now also providing the possibility to also pass the content type as parameter. This version allows the explicit passing of a session id as string. This makes it possible to also use this function within a thread outside the request/response processing.- Parameters:
sessionId
- Session id of the session to store the file.
-
clear
public static void clear(javax.servlet.http.HttpSession session) Clear complete content of file manager for the current session.- Parameters:
session
-
-
updateFilePathToOverComeDifferentFileNames
-