Class FileBasedUploadFilter
java.lang.Object
de.espirit.firstspirit.server.mediamanagement.FileBasedUploadFilter
- All Implemented Interfaces:
SetServiceLocatorCallback,UploadFilter,Closeable,AutoCloseable
public abstract class FileBasedUploadFilter
extends Object
implements UploadFilter, SetServiceLocatorCallback
A basic file based implementation of a
UploadFilter.- Since:
- 4.1
- Example:
- This is a basic example how to extend this class
import de.espirit.firstspirit.server.mediamanagement.*; import de.espirit.firstspirit.access.store.mediastore.UploadRejectedException; import java.io.File; import java.io.IOException; public class FileBasedUploadFilterExample extends FileBasedUploadFilter { /** * IOException indicates to not store the File tempFile in the repository * * @param tempFile * @throws java.io.IOException */ @Override public void doFilter(final File tempFile) throws IOException { final boolean failure = false; // do something. for example scan the <code>tempFile</code> for a virus //scan(tempFile) if (failure) { // indicates not to store the File tempFile in the repository throw new UploadRejectedException("A Virus has been found."); } } }
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Callback method which may be used to do some clean up.abstract voidIOException indicates to not store the File tempFile in the repositoryprotected ServiceLocatorGets the current service locator.protected voidinit()Method stub.voidinitUploadFilter(@NotNull InputStream in, @NotNull String extension) Creates a new tempfile with the given extension and copies the given inputstream to this tempfile.intread(@org.jetbrains.annotations.NotNull byte[] b, int off, int len) Reads up to len bytes of data from the input stream into an array of bytes.final voidsetServiceLocator(@NotNull ServiceLocator value) Set a service locator which will be used to lookup a service.
-
Constructor Details
-
FileBasedUploadFilter
public FileBasedUploadFilter()
-
-
Method Details
-
setServiceLocator
Set a service locator which will be used to lookup a service.- Specified by:
setServiceLocatorin interfaceSetServiceLocatorCallback- Parameters:
value-- Since:
- 4.1
-
init
protected void init()Method stub. Override to init some filter stuff.- Since:
- 4.1
-
getServiceLocator
Gets the current service locator.- Returns:
- the service locator
- Since:
- 4.1
-
initUploadFilter
public void initUploadFilter(@NotNull @NotNull InputStream in, @NotNull @NotNull String extension) throws IOException Creates a new tempfile with the given extension and copies the given inputstream to this tempfile. Initialize the filter instance. It is not allowed to change the content of the data provided by in.- Specified by:
initUploadFilterin interfaceUploadFilter- Parameters:
in- input stream containing the dataextension- file extension - it is not save to guess the file content from this extension- Throws:
IOException- indicates to not store the File tempFile in the repository- Since:
- 4.1
-
doFilter
IOException indicates to not store the File tempFile in the repository- Parameters:
tempFile- the temp file- Throws:
IOException- indicates to not store the File tempFile in the repository- Since:
- 4.1
-
read
public int read(@NotNull @org.jetbrains.annotations.NotNull byte[] b, int off, int len) throws IOException Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read should returned as an integer. SeeInputStream.read(byte[], int, int).- Specified by:
readin interfaceUploadFilter- Parameters:
b- the bytes to readoff- the offsetlen- the length- Returns:
- the int The number of bytes actually read
- Throws:
IOException- on any error- Since:
- 4.1
-
close
public void close()Callback method which may be used to do some clean up. A call to this method should at least close the input stream provided in methodUploadFilter.initUploadFilter(java.io.InputStream, String). Closes the stream and the tempfile used for this file based implementation.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceUploadFilter- Since:
- 4.1
-