@@ -198,6 +198,7 @@ private void processHeader(Socket clientSocket, String header) throws ServerRunT
198
198
199
199
this .totalFileSize = Long .parseLong (headerInfo .nextLine ());
200
200
generalFileName = headerInfo .nextLine ();
201
+ System .out .println (header );
201
202
202
203
this .notifyAddToTransferenceObservers (generalFileName , src_addr );
203
204
while (headerInfo .hasNextLine ()){
@@ -238,6 +239,7 @@ else if(fileInfo.charAt(0) == 'F'){ //File
238
239
239
240
private void receiveFile (Socket clientSocket , String filePath , Long fileSize ) throws ServerRunTimeException {
240
241
try {
242
+ System .out .println (filePath + " " + fileSize );
241
243
filePath .replace ("\\ " , "\\ \\ " );
242
244
this .output = new DataOutputStream (new BufferedOutputStream (new FileOutputStream (new File (filePath ))));
243
245
@@ -249,20 +251,24 @@ private void receiveFile(Socket clientSocket, String filePath, Long fileSize) th
249
251
integerMaxValueExceeded = false ;
250
252
}
251
253
252
- int bytesReaded ;
254
+ int bytesReaded = 0 ;
253
255
long totalBytesReaded = 0 ;
256
+ // EL problema está en que nunca se decrementa dentro la variable integerFilesize por lo que se lanza con valor fileSize hasta que chupa todo el buffer
254
257
while (integerFileSizeValue > 0 && (bytesReaded = this .input .read (this .buffer , 0 , Math .min (this .BUFFERSIZE , integerFileSizeValue ))) >= 0 ){
255
258
this .output .write (this .buffer , 0 , bytesReaded );
256
259
this .output .flush ();
260
+ //System.out.println(bytesReaded);
257
261
fileSize -= bytesReaded ;
258
262
259
263
totalBytesReaded += bytesReaded ;
260
264
if (integerMaxValueExceeded && fileSize < Integer .MAX_VALUE ){
261
265
integerFileSizeValue = Math .toIntExact (fileSize );
262
266
integerMaxValueExceeded = false ;
263
267
}
268
+ System .out .println (filePath + " " +integerFileSizeValue );
264
269
this .notifyUpdateToTransferenceObservers (this .getProgress (totalBytesReaded ), clientSocket .getInetAddress ().toString ().substring (1 ));
265
270
}
271
+ //System.out.println(bytesReaded);
266
272
}
267
273
catch (FileNotFoundException e ){
268
274
this .notifyRemoveToTransferenceObservers (clientSocket .getInetAddress ().toString ().substring (1 ));
0 commit comments