public class SocketThread extends java.lang.Thread
Modifier and Type | Field and Description |
---|---|
private java.net.Socket |
connectionSocket |
private java.io.File |
directory |
private OutputDataParser |
outputDataParser |
Constructor and Description |
---|
SocketThread(java.net.Socket connectionSocket,
java.io.File directory) |
Modifier and Type | Method and Description |
---|---|
private void |
closeSocket()
Closes the socket and handles a possible exception by interrupting
this thread.
|
private void |
handleConnection()
Handles a request through the socket connection.
|
private java.lang.String |
readFromClient()
Listens to the socket and reads one line of input data from the client,
that is, receives a potential HTTP request.
|
void |
run()
Handles the connection and closes socket when done.
|
private void |
sendErrorMessageToClient(java.io.DataOutputStream outToClient,
java.lang.String message)
Sends the input error message to the client over the socket by using the
input data output stream after having converted it to a simple html page.
|
private void |
sendFileToClient(java.io.DataOutputStream outToClient,
java.io.File file)
Sends the input file to the client over the socket by using the input
data output stream.
|
private void |
sendHeaderToClient(java.io.DataOutputStream outToClient,
Header header)
Sends the input file header to the client over the socket by using
the input data output stream.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
private java.net.Socket connectionSocket
private java.io.File directory
private OutputDataParser outputDataParser
public SocketThread(java.net.Socket connectionSocket, java.io.File directory)
private java.lang.String readFromClient() throws java.io.IOException
java.io.IOException
- - If an error occurs reading data or if the data read
was null.private void sendHeaderToClient(java.io.DataOutputStream outToClient, Header header) throws java.io.IOException
outToClient:
- DataOutputStream - The stream connected to the socket.header:
- Header - The header to be sent.java.io.IOException
- - If an error occurs trying to send the header.private void sendFileToClient(java.io.DataOutputStream outToClient, java.io.File file) throws java.io.IOException
outToClient:
- DataOutputStream - The stream connected to the socket.file:
- File - The file to be sent.java.io.IOException
- - If an error occurs trying to read/send the file.private void sendErrorMessageToClient(java.io.DataOutputStream outToClient, java.lang.String message) throws java.io.IOException
outToClient:
- DataOutputStream - The stream connected to the socket.message:
- String - The error message.java.io.IOException
- - If an error occurs trying to send the page.private void handleConnection() throws java.io.IOException
java.io.IOException
- - If an error occurs reading/writing data to/from
the socket or if opening/flushing/closing streams fails.private void closeSocket()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread