@@ -79,17 +79,17 @@ public static void visitAllDirsAndFiles(File dir) throws Exception{
7979 oos .flush ();
8080
8181 // receive SEND or RECEIVE
82- Boolean updateToServer = (Boolean ) ois .readObject (); //if true update server, else update from server
82+ Integer updateToServer = (Integer ) ois .readObject (); //if true update server, else update from server
8383
84- if (updateToServer ) { // send file to server
84+ if (updateToServer == 1 ) { // send file to server
8585 sendFile (dir );
8686
8787 ois .readObject (); // make sure server got the file
8888
89- } else { // update file from server.
89+ } else if ( updateToServer == 0 ) { // update file from server.
9090 dir .delete (); // first delete the current file
9191
92- oos .writeObject (new Boolean (true )); // send "Ready"
92+ oos .writeObject (new Boolean (true )); // send "Ready"
9393 oos .flush ();
9494
9595 receiveFile (dir );
@@ -99,14 +99,9 @@ public static void visitAllDirsAndFiles(File dir) throws Exception{
9999
100100 Long updateLastModified = (Long ) ois .readObject (); // update the last modified date for this file from the server
101101 dir .setLastModified (updateLastModified );
102-
103- oos .close ();
104- ois .close ();
105- }
102+
103+ } // no need to check if update to server == 2 because we do nothing here
106104 }
107-
108- /* debug */ System .out .println ("Name: " + dir .getName () + " Dir: " + dir .isDirectory () + " Modified: " + dir .lastModified () + " Size: " + dir .length ());
109-
110105 if (dir .isDirectory ()) {
111106 String [] children = dir .list ();
112107 for (int i =0 ; i <children .length ; i ++) {
@@ -125,7 +120,6 @@ public static void sendFile(File dir) throws Exception {
125120 {
126121 oos .write (buff ,0 ,bytesRead );
127122 }
128- oos .flush ();
129123 in .close ();
130124 // after sending a file you need to close the socket and reopen one.
131125 oos .flush ();
@@ -135,6 +129,8 @@ public static void sendFile(File dir) throws Exception {
135129 sock = new Socket (serverIP , PORT_NUMBER );
136130 oos = new ObjectOutputStream (sock .getOutputStream ());
137131 ois = new ObjectInputStream (sock .getInputStream ());
132+
133+ printDebug (true , dir );
138134 }
139135
140136 public static void receiveFile (File dir ) throws Exception {
@@ -154,6 +150,8 @@ public static void receiveFile(File dir) throws Exception {
154150 sock = new Socket (serverIP , PORT_NUMBER );
155151 ois = new ObjectInputStream (sock .getInputStream ());
156152 oos = new ObjectOutputStream (sock .getOutputStream ());
153+
154+ printDebug (false , dir );
157155 }
158156
159157 public static void updateFromServer (Socket sock , String fullDirName ) throws Exception {
@@ -165,4 +163,12 @@ public static void updateFromServer(Socket sock, String fullDirName) throws Exce
165163// need to implement this part
166164
167165 }
166+
167+ public static void printDebug (Boolean sending , File dir ){
168+ if (sending )
169+ System .out .println ("SEND=Name: " + dir .getName () + " Dir: " + dir .isDirectory () + " Modified: " + dir .lastModified () + " Size: " + dir .length ());
170+ else
171+ System .out .println ("RECV=Name: " + dir .getName () + " Dir: " + dir .isDirectory () + " Modified: " + dir .lastModified () + " Size: " + dir .length ());
172+
173+ }
168174}
0 commit comments