Class TempFileManager

java.lang.Object
org.eclnt.jsfserver.util.tempfile.TempFileManager

public class TempFileManager extends Object
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 TempFileAccessServlet.

The content is automatically removed from the temporary file system when the session is closed.
  • Field Details

  • Constructor Details

    • TempFileManager

      public TempFileManager()
  • Method Details

    • initialize

      public static void initialize(javax.servlet.ServletContext servletContext)
      Internally called during start up of server.
    • initTempFileDirectory

      public static void initTempFileDirectory(String directory)
      By default the servlet temp directory is used for storing the temporary files. But: you may define some own directory as well.
    • readTempFile

      public static byte[] readTempFile(javax.servlet.http.HttpSession session, String path)
      Read the content of the temp file manager.
      Parameters:
      session -
      path -
      Returns:
    • findTempFileContentType

      public static String findTempFileContentType(javax.servlet.http.HttpSession session, String path)
      Read the content type - if it was passed when calling saveTempFile(String, String, byte[]).
    • findTempFileContentType

      public static String findTempFileContentType(String sessionId, String path)
      Read the content type - if it was passed when calling saveTempFile(String, String, byte[]).
    • findTempFileContentType

      public static String findTempFileContentType(String filePathOfSavedFile)
      Read the content type for a file that was written.
    • findTempFilePath

      public static String findTempFilePath(javax.servlet.http.HttpSession session, String path)
      Finds the location of the temp file.
      Parameters:
      session -
      path -
      Returns:
    • findTempFilePath

      public static String findTempFilePath(String sessionId, String path)
      Finds the location of the temp file.
      Parameters:
      session -
      path -
      Returns:
    • saveTempFile

      public static String saveTempFile(String fileName, byte[] content)
      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

      public static String saveTempFile(String fileName, String contentType, byte[] content)
      Extended version of saveTempFile(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

      public static String saveTempFileCrossSession(String fileName, String contentType, byte[] content)
      Same as saveTempFile(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 of saveTempFile(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 -
    • calculateURL

      public static String calculateURL(String path, String fileName, boolean withURLSessionIdEncoding)
      Calculates the URL that accesses a file within the TempFileManager.
    • calculateFilePath

      public static String calculateFilePath(String httpSessionId, String path)
      Calculates the full file path for a file that is stored in the TempFileManager.

      You may use this file path to store own data - which will be automatically removed by the TempFileManager at the end of the session.
    • calculateDirectoryPath

      public static String calculateDirectoryPath(String httpSessionId)
      Calculates the directory path for the directory that is opened up for each session within the TempFileManager. The content of the directory is removed automatically at the end of the http session.
    • updateFilePathToOverComeDifferentFileNames

      public static String updateFilePathToOverComeDifferentFileNames(String filePath)