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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Callback method which may be used to do some clean up.abstract void
IOException indicates to not store the File tempFile in the repositoryprotected ServiceLocator
Gets the current service locator.protected void
init()
Method stub.void
initUploadFilter
(@NotNull InputStream in, @NotNull String extension) Creates a new tempfile with the given extension and copies the given inputstream to this tempfile.int
read
(@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 void
setServiceLocator
(@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:
setServiceLocator
in 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:
initUploadFilter
in 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:
read
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceUploadFilter
- Since:
- 4.1
-