at.gv.egiz.pdfas.web.helper
Class TempDirHelper

java.lang.Object
  extended byat.gv.egiz.pdfas.web.helper.TempDirHelper

public class TempDirHelper
extends Object

Author:
wprinz

Field Summary
protected static long runningIndex
           
 
Constructor Summary
TempDirHelper()
           
 
Method Summary
static File assembleTemporaryDirectoryFile()
          Assembles the File of the temporary directory without checking if it really exists.
static void clearTemporaryDirectory()
          Deletes all files in the temporary directory, if it exists.
static DataSink createTempDataSink(String fileNameSuffix)
           
protected static File createTempFileInDir(String fileName)
           
static void deleteDataSinkIfFileBased(DataSink dataSink)
           
static void deleteDataSourceIfFileBased(DataSource dataSource)
          Deletes the underlying file of the FileBased DataSource.
static String extractFileNameSuffix(String file)
          Given a file (maybe with path), extracts the file name suffix.
protected static String formatFileName(String fileNameSuffix)
           
protected static String formatIndex(long index)
           
static File formTempFile(String fileNameSuffix)
           
protected static File getFileInTempDir(String fileName)
           
static File getTemporaryDirectory()
          Returns the directory where temporary files should be stored.
static boolean isReasonableToStore(int textLength)
          Tells, if it is reasonable to store the text of the given length onto the disk.
static File placeInputIntoTempDirFile(InputStream input, String fileNameSuffix)
           
static PdfDataSource placePdfIntoTempDir(InputStream pdfInput, String fileNameSuffix)
           
static TextDataSource placeTextIntoTempDir(String text, String fileNameSuffix)
          Places the text into the temp dir if reasonable.
static void storeTextSignatureHoldersIfApplicable(List shs, String fileNameSuffix)
           
static void writeDataSinkToHttpResponse(DataSink ds, HttpServletResponse response)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

runningIndex

protected static long runningIndex
Constructor Detail

TempDirHelper

public TempDirHelper()
Method Detail

assembleTemporaryDirectoryFile

public static File assembleTemporaryDirectoryFile()
Assembles the File of the temporary directory without checking if it really exists.


getTemporaryDirectory

public static File getTemporaryDirectory()
Returns the directory where temporary files should be stored.

If the directory doesn't exist, it is created.

Returns:
Returns the directory where temporary files should be stored.

clearTemporaryDirectory

public static void clearTemporaryDirectory()
Deletes all files in the temporary directory, if it exists.

This should be used to clear temporary files when the application shuts down.


storeTextSignatureHoldersIfApplicable

public static void storeTextSignatureHoldersIfApplicable(List shs,
                                                         String fileNameSuffix)
                                                  throws IOException
Throws:
IOException

placeTextIntoTempDir

public static TextDataSource placeTextIntoTempDir(String text,
                                                  String fileNameSuffix)
                                           throws IOException
Places the text into the temp dir if reasonable.

Reasonable means that the text is longer than a certain threshold. Otherwise a short text is simply held in memory.

Parameters:
text - The text to be stored.
fileNameSuffix - A file name suffix so that the temp file gets a more "readable" name.
Returns:
Returns the TextDataSource.
Throws:
IOException - F.e.

isReasonableToStore

public static boolean isReasonableToStore(int textLength)
Tells, if it is reasonable to store the text of the given length onto the disk.

Parameters:
textLength - The length of the text under question.
Returns:
Returns true if the text should be stored on the disk.

placePdfIntoTempDir

public static PdfDataSource placePdfIntoTempDir(InputStream pdfInput,
                                                String fileNameSuffix)
                                         throws IOException
Throws:
IOException

placeInputIntoTempDirFile

public static File placeInputIntoTempDirFile(InputStream input,
                                             String fileNameSuffix)
                                      throws IOException
Throws:
IOException

formTempFile

public static File formTempFile(String fileNameSuffix)

getFileInTempDir

protected static File getFileInTempDir(String fileName)

formatFileName

protected static String formatFileName(String fileNameSuffix)

formatIndex

protected static String formatIndex(long index)

createTempFileInDir

protected static File createTempFileInDir(String fileName)
                                   throws IOException
Throws:
IOException

createTempDataSink

public static DataSink createTempDataSink(String fileNameSuffix)
                                   throws IOException
Throws:
IOException

writeDataSinkToHttpResponse

public static void writeDataSinkToHttpResponse(DataSink ds,
                                               HttpServletResponse response)
                                        throws IOException
Throws:
IOException

deleteDataSourceIfFileBased

public static void deleteDataSourceIfFileBased(DataSource dataSource)
Deletes the underlying file of the FileBased DataSource.

If the DataSource is not FileBased, nothing is done.

This is usually used by the application to delete temporary files.

Parameters:
dataSource -

deleteDataSinkIfFileBased

public static void deleteDataSinkIfFileBased(DataSink dataSink)

extractFileNameSuffix

public static String extractFileNameSuffix(String file)
Given a file (maybe with path), extracts the file name suffix.

Parameters:
file - The file and maybe path.
Returns:
Returns the file name.


Copyright © 2006-2010. All Rights Reserved.