org.eclnt.jsfserver.util.tempfile

## Class TempFileManager

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

-     public class TempFileManager
      extends java.lang.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `CROSS_SESSION_SESSIONID`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TempFileManager()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `clear(HttpSession session)` Clear complete content of file manager for the current session.
    `static java.lang.String` | `findTempFileContentType(HttpSession session, java.lang.String path)` Read the content type - if it was passed when calling `saveTempFile(String, String, byte[])`.
    `static java.lang.String` | `findTempFilePath(HttpSession session, java.lang.String path)` Finds the location of the temp file.
    `static void` | `initialize(ServletContext servletContext)` Internally called during start up of server.
    `static void` | `initTempFileDirectory(java.lang.String directory)` By default the servlet temp directory is used for storing the temporary files.
    `static byte[]` | `readTempFile(HttpSession session, java.lang.String path)` Read the content of the temp file manager.
    `static java.lang.String` | `saveTempFile(java.lang.String fileName, byte[] content)`
    `static java.lang.String` | `saveTempFile(java.lang.String fileName, java.lang.String contentType, byte[] content)` Extended version of `saveTempFile(String, byte[])`, now also providing the possibility to also pass the content type as parameter.
    `static java.lang.String` | `saveTempFile(java.lang.String fileName, java.lang.String contentType, byte[] content, java.lang.String sessionId)` Extended version of `saveTempFile(String, byte[])`, now also providing the possibility to also pass the content type as parameter.
    `static java.lang.String` | `saveTempFileCrossSession(java.lang.String fileName, java.lang.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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CROSS_SESSION_SESSIONID

          public static final java.lang.String CROSS_SESSION_SESSIONID

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TempFileManager

          public TempFileManager()

  - ### Method Detail

    - #### initialize

          public static void initialize(ServletContext servletContext)

      Internally called during start up of server.

    - #### initTempFileDirectory

          public static void initTempFileDirectory(java.lang.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(HttpSession session,
                                            java.lang.String path)

      Read the content of the temp file manager.
      Parameters:
        `session` -
        `path` -
      Returns:

    - #### findTempFileContentType

          public static java.lang.String findTempFileContentType(HttpSession session,
                                                                 java.lang.String path)

      Read the content type - if it was passed when calling `saveTempFile(String, String, byte[])`.

    - #### findTempFilePath

          public static java.lang.String findTempFilePath(HttpSession session,
                                                          java.lang.String path)

      Finds the location of the temp file.
      Parameters:
        `session` -
        `path` -
      Returns:

    - #### saveTempFile

          public static java.lang.String saveTempFile(java.lang.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 java.lang.String saveTempFile(java.lang.String fileName,
                                                      java.lang.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 java.lang.String saveTempFileCrossSession(java.lang.String fileName,
                                                                  java.lang.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 java.lang.String saveTempFile(java.lang.String fileName,
                                                      java.lang.String contentType,
                                                      byte[] content,
                                                      java.lang.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(HttpSession session)

      Clear complete content of file manager for the current session.
      Parameters:
        `session` -

Copyright © CaptainCasa Gmbh. All Rights Reserved.