public class FileReceiver
extends java.lang.Object
implements java.lang.Runnable
FileReceiver is used for receiving any kind of file from the client.
The file extension is specified in the constructor. | Modifier and Type | Field and Description |
|---|---|
private int |
bufferSize
Size of the buffer used to receive a file.
|
private java.lang.String |
clientId
Identifier of the client requesting the transmission.
|
private java.lang.Thread |
fileReceiverThread
Thread used by the class.
|
private static org.apache.log4j.Logger |
log
Used to log different events.
|
private java.io.File |
masterFolder
The main folder of the VBS server.
|
private java.io.File |
myFile
File received from the client.
|
private java.lang.String |
myFileExtension
Extension which will be assigned to the received file.
|
private java.net.Socket |
mySocket
Socket used to communicate with the client.
|
static java.lang.String |
PERMISSION_ACCEPT_MESSAGE
Message sent to the server when the transfer is accepted.
|
static java.lang.String |
PERMISSION_REJECT_MESSAGE
Message sent to the server when the transfer is rejected.
|
private long |
transferEndTime
Timestamp when the file transfer finished.
|
private long |
transferStartTime
Timestamp when the file transfer started.
|
| Constructor and Description |
|---|
FileReceiver(java.net.Socket mySocket,
java.io.File masterFolder,
java.lang.String myFileExtension)
Constructs the object.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
authenticateClient()
Tries to authenticate the client by checking if the client identifier looks as valid.
|
private void |
receiveFile()
Receives the file from the client.
|
void |
run()
Runs the client.
|
void |
start()
Starts the thread.
|
private static org.apache.log4j.Logger log
private java.lang.Thread fileReceiverThread
public static final java.lang.String PERMISSION_ACCEPT_MESSAGE
public static final java.lang.String PERMISSION_REJECT_MESSAGE
private int bufferSize
private java.io.File masterFolder
private java.lang.String myFileExtension
private java.net.Socket mySocket
private java.lang.String clientId
private long transferStartTime
private long transferEndTime
private java.io.File myFile
public FileReceiver(java.net.Socket mySocket,
java.io.File masterFolder,
java.lang.String myFileExtension)
mySocket - socket used to communicate with the clientmasterFolder - main folder of the VBS servermyFileExtension - extension assigned to the received filepublic void start()
public void run()
run in interface java.lang.Runnableprivate boolean authenticateClient()
throws java.io.IOException
true if the client was authenticated, false if they client was rejectedjava.io.IOException - if a communication problem occursprivate void receiveFile()
throws java.io.IOException
java.io.IOException - if a communication problem occurs