|
@@ -24,6 +24,7 @@ package com.dmdirc.addons.dcc.io;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.addons.dcc.DCCTransferHandler;
|
26
|
26
|
import com.dmdirc.util.collections.ListenerList;
|
|
27
|
+import com.dmdirc.util.io.StreamUtils;
|
27
|
28
|
|
28
|
29
|
import java.io.DataInputStream;
|
29
|
30
|
import java.io.DataOutputStream;
|
|
@@ -298,7 +299,7 @@ public class DCCTransfer extends DCC {
|
298
|
299
|
* @return starting position of file.
|
299
|
300
|
*/
|
300
|
301
|
public int getFileStart() {
|
301
|
|
- return this.startpos;
|
|
302
|
+ return startpos;
|
302
|
303
|
}
|
303
|
304
|
|
304
|
305
|
/**
|
|
@@ -317,7 +318,7 @@ public class DCCTransfer extends DCC {
|
317
|
318
|
transferFile = new File(filename);
|
318
|
319
|
if (transferType == TransferType.RECEIVE) {
|
319
|
320
|
fileOut = new DataOutputStream(new FileOutputStream(
|
320
|
|
- transferFile.getAbsolutePath(), (startpos > 0)));
|
|
321
|
+ transferFile.getAbsolutePath(), startpos > 0));
|
321
|
322
|
}
|
322
|
323
|
out = new DataOutputStream(socket.getOutputStream());
|
323
|
324
|
in = new DataInputStream(socket.getInputStream());
|
|
@@ -333,18 +334,8 @@ public class DCCTransfer extends DCC {
|
333
|
334
|
@Override
|
334
|
335
|
protected void socketClosed() {
|
335
|
336
|
// Try to close both, even if one fails.
|
336
|
|
- if (out != null) {
|
337
|
|
- try {
|
338
|
|
- out.close();
|
339
|
|
- } catch (IOException e) {
|
340
|
|
- }
|
341
|
|
- }
|
342
|
|
- if (in != null) {
|
343
|
|
- try {
|
344
|
|
- in.close();
|
345
|
|
- } catch (IOException e) {
|
346
|
|
- }
|
347
|
|
- }
|
|
337
|
+ StreamUtils.close(out);
|
|
338
|
+ StreamUtils.close(in);
|
348
|
339
|
out = null;
|
349
|
340
|
in = null;
|
350
|
341
|
|
|
@@ -384,7 +375,7 @@ public class DCCTransfer extends DCC {
|
384
|
375
|
try {
|
385
|
376
|
final byte[] data = new byte[blockSize];
|
386
|
377
|
final int bytesRead = in.read(data);
|
387
|
|
- readSize = readSize + bytesRead;
|
|
378
|
+ readSize += bytesRead;
|
388
|
379
|
|
389
|
380
|
if (bytesRead > 0) {
|
390
|
381
|
for (DCCTransferHandler handler : handlers.get(DCCTransferHandler.class)) {
|
|
@@ -443,7 +434,7 @@ public class DCCTransfer extends DCC {
|
443
|
434
|
int bytesReceived;
|
444
|
435
|
do {
|
445
|
436
|
bytesReceived = in.readInt();
|
446
|
|
- } while ((readSize - bytesReceived) > 0);
|
|
437
|
+ } while (readSize - bytesReceived > 0);
|
447
|
438
|
}
|
448
|
439
|
|
449
|
440
|
if (readSize == size) {
|
|
@@ -462,7 +453,7 @@ public class DCCTransfer extends DCC {
|
462
|
453
|
} catch (IOException e) {
|
463
|
454
|
break;
|
464
|
455
|
}
|
465
|
|
- } while (ack > 0 && (readSize - ack) > 0);
|
|
456
|
+ } while (ack > 0 && readSize - ack > 0);
|
466
|
457
|
}
|
467
|
458
|
|
468
|
459
|
return false;
|