Interface UploadFilter

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
FileBasedUploadFilter

public interface UploadFilter extends Closeable
The interface Upload filter.
Since:
4.1
See Also:
Example:
A basic example of FileBasedUploadFilter
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.");
		}
	}
}
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Callback method which may be used to do some clean up.
    void
    initUploadFilter(@NotNull InputStream in, @NotNull String extension)
    Initialize the filter instance.
    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.
  • Method Details

    • initUploadFilter

      void initUploadFilter(@NotNull @NotNull InputStream in, @NotNull @NotNull String extension) throws IOException
      Initialize the filter instance. It is not allowed to change the content of the data provided by in.
      Parameters:
      in - input stream containing the data
      extension - file extension - it is not save to guess the file content from this extension
      Throws:
      IOException - the iO exception
      Since:
      4.1
    • read

      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. See InputStream.read(byte[], int, int).
      Parameters:
      b - the bytes to read
      off - the offset
      len - the length
      Returns:
      the int The number of bytes actually read
      Throws:
      IOException - on any error
      Since:
      4.1
    • close

      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 method initUploadFilter(java.io.InputStream, String).
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Since:
      4.1