-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChunkServer_permissionListener.java
More file actions
79 lines (65 loc) · 2.35 KB
/
Copy pathChunkServer_permissionListener.java
File metadata and controls
79 lines (65 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Created and edited by: Sahil Pethe (ssp5329@g.rit.edu)
* Sukraat Ahluwalia (sxa4430@g.rit.edu)
*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ChunkServer_permissionListener implements Runnable{
public String sendFilePerms(String fileName){
// we get the file path of the file that needs permission checking
File temp = new File(Paths.get("").toAbsolutePath().toString()+"/cached_data/"+fileName);
boolean isWrite = temp.canWrite();
boolean isRead = temp.canRead();
boolean isExec = temp.canExecute();
// we keep on adding the file permissions one by one
String perms = "";
if(isWrite){
perms += "-";
}else{
perms += "w";
}
if(isRead){
perms += "-";
}else{
perms += "r";
}
if(isExec){
perms += "-";
}else{
perms += "x";
}
return perms;
}
@Override
public void run() {
while(true){
try {
System.out.println("Chunk Server listening on port number 9000");
// creating new server socket
ServerSocket ss = new ServerSocket(9000);
//accepting incoming user connection
Socket s = ss.accept();
// creating data input stream for reading the file name
DataInputStream din = new DataInputStream(s.getInputStream());
String str = din.readUTF();
String perms = sendFilePerms(str);
// sending the permissions using data output stream
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
dout.writeUTF(perms);
// closing the socket connections
s.close();
ss.close();
} catch (IOException ex) {
Logger.getLogger(MasterNode_reallocate.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}