2.17.2: 2011-06-17

net.sf.basedb.ws.server
Class TempFileDataSource

java.lang.Object
  extended by javax.activation.FileDataSource
      extended by net.sf.basedb.ws.server.TempFileDataSource
All Implemented Interfaces:
DataSource

public class TempFileDataSource
extends FileDataSource

A DataSource implementation for temporary files. The temporary file will be deleted once the entire file has been read or the close() method is called on the InputStream.

Since this may cause problems if the getInputStream() is called more than once, the file deletion is disabled if that happens. Instead the File.deleteOnExit() is called to mark the file for deletion when the virtual machine exits.

Version:
2.5
Author:
nicklas
Last modified
$Date: 2008-09-11 22:06:36 +0200 (Thu, 11 Sep 2008) $

Nested Class Summary
private  class TempFileDataSource.TempInputStream
          An InputStream implementation that deletes the source file once the entire stream has been read (=any of the read() methods return -1) or when close() is called.
 
Field Summary
private  String mimeType
           
private  int numStreams
           
 
Constructor Summary
TempFileDataSource(File file, String mimeType)
           
 
Method Summary
 String getContentType()
          Get the supplied MIME type, if any.
 InputStream getInputStream()
          Get an InputStream that deletes the source file as soon as the end of file is reached or close() is called.
 
Methods inherited from class javax.activation.FileDataSource
getFile, getName, getOutputStream, setFileTypeMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mimeType

private final String mimeType

numStreams

private int numStreams
Constructor Detail

TempFileDataSource

public TempFileDataSource(File file,
                          String mimeType)
Method Detail

getContentType

public String getContentType()
Get the supplied MIME type, if any. Otherwise call super.getContentType().

Specified by:
getContentType in interface DataSource
Overrides:
getContentType in class FileDataSource

getInputStream

public InputStream getInputStream()
                           throws IOException
Get an InputStream that deletes the source file as soon as the end of file is reached or close() is called. If this method is called more than once the file deletion is disabled since it may interfere with other streams.

Specified by:
getInputStream in interface DataSource
Overrides:
getInputStream in class FileDataSource
Throws:
IOException

2.17.2: 2011-06-17