Package controller.utils
Class FileServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
controller.utils.FileServlet
- All Implemented Interfaces:
java.io.Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
@WebServlet(name="FileServlet",
urlPatterns="/file/*",
loadOnStartup=0)
public class FileServlet
extends javax.servlet.http.HttpServlet
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
FileServlet.Range
This class represents a byte range. -
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
basePath
BasePath dove vengono messe le immagini.private static int
DEFAULT_BUFFER_SIZE
Size del buffer.private static long
DEFAULT_EXPIRE_TIME
Expire time.private static java.lang.String
MULTIPART_BOUNDARY
Multipart byteranges. -
Constructor Summary
Constructors Constructor Description FileServlet()
-
Method Summary
Modifier and Type Method Description private static boolean
accepts(java.lang.String acceptHeader, java.lang.String toAccept)
Returns true if the given accept header accepts the given value.private static void
close(java.io.Closeable resource)
Close the given resource.private static void
copy(java.io.RandomAccessFile input, java.io.OutputStream output, long start, long length)
Copy the given byte range of the given input to the given output.void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Process GET request.protected void
doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Process HEAD request.private java.io.File
helper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Help the actual request.void
init()
Initialize the servlet.private static boolean
matches(java.lang.String matchHeader, java.lang.String toMatch)
Returns true if the given match header matches the given value.private void
processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean content)
Process the actual request.private static long
sublong(java.lang.String value, int beginIndex, int endIndex)
Returns a substring of the given string value from the given begin index to the given end index as a long.static java.util.List<java.lang.String>
uploadFoto(javax.servlet.http.HttpServletRequest request)
Metodo per upload delle foto.Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZESize del buffer.- See Also:
- Constant Field Values
-
DEFAULT_EXPIRE_TIME
private static final long DEFAULT_EXPIRE_TIMEExpire time.- See Also:
- Constant Field Values
-
MULTIPART_BOUNDARY
private static final java.lang.String MULTIPART_BOUNDARYMultipart byteranges.- See Also:
- Constant Field Values
-
basePath
private static java.lang.String basePathBasePath dove vengono messe le immagini.
-
-
Constructor Details
-
FileServlet
public FileServlet()
-
-
Method Details
-
init
public void init() throws javax.servlet.ServletExceptionInitialize the servlet.- Overrides:
init
in classjavax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
-
doHead
protected void doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOExceptionProcess HEAD request. This returns the same headers as GET request, but without content.- Overrides:
doHead
in classjavax.servlet.http.HttpServlet
- Throws:
java.io.IOException
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOExceptionProcess GET request.- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
java.io.IOException
-
processRequest
private void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean content) throws java.io.IOExceptionProcess the actual request.- Parameters:
request
- The request to be processed.response
- The response to be created.content
- Whether the request body should be written (GET) or not (HEAD).- Throws:
java.io.IOException
- If something fails at I/O level.
-
helper
private java.io.File helper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOExceptionHelp the actual request.- Parameters:
request
- The request to be processed.response
- The response to be created.- Returns:
- file
- Throws:
java.io.IOException
- If something fails at I/O level.
-
accepts
private static boolean accepts(java.lang.String acceptHeader, java.lang.String toAccept)Returns true if the given accept header accepts the given value.- Parameters:
acceptHeader
- The accept header.toAccept
- The value to be accepted.- Returns:
- True if the given accept header accepts the given value.
-
matches
private static boolean matches(java.lang.String matchHeader, java.lang.String toMatch)Returns true if the given match header matches the given value.- Parameters:
matchHeader
- The match header.toMatch
- The value to be matched.- Returns:
- True if the given match header matches the given value.
-
sublong
private static long sublong(java.lang.String value, int beginIndex, int endIndex)Returns a substring of the given string value from the given begin index to the given end index as a long. If the substring is empty, then -1 will be returned- Parameters:
value
- The string value to return a substring as long for.beginIndex
- The begin index of the substring to be returned as long.endIndex
- The end index of the substring to be returned as long.- Returns:
- A substring of the given string value as long or -1 if substring is empty.
-
copy
private static void copy(java.io.RandomAccessFile input, java.io.OutputStream output, long start, long length) throws java.io.IOExceptionCopy the given byte range of the given input to the given output.- Parameters:
input
- The input to copy the given range to the given output for.output
- The output to copy the given range from the given input for.start
- Start of the byte range.length
- Length of the byte range.- Throws:
java.io.IOException
- If something fails at I/O level.
-
close
private static void close(java.io.Closeable resource)Close the given resource.- Parameters:
resource
- The resource to be closed.
-
uploadFoto
public static java.util.List<java.lang.String> uploadFoto(javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException, java.io.IOExceptionMetodo per upload delle foto.- Parameters:
request
- Request da dove prelevare le foto- Returns:
- lista dei nomi dei file
- Throws:
javax.servlet.ServletException
java.io.IOException
-