1
1
/*
2
- * Copyright (c) 2009, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2009, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -1217,7 +1217,6 @@ public sun.net.ftp.FtpClient setRestartOffset(long offset) {
1217
1217
* @throws IOException if the transfer fails.
1218
1218
*/
1219
1219
public sun .net .ftp .FtpClient getFile (String name , OutputStream local ) throws sun .net .ftp .FtpProtocolException , IOException {
1220
- int mtu = 1500 ;
1221
1220
if (restartOffset > 0 ) {
1222
1221
Socket s ;
1223
1222
try {
@@ -1227,27 +1226,15 @@ public sun.net.ftp.FtpClient getFile(String name, OutputStream local) throws sun
1227
1226
}
1228
1227
issueCommandCheck ("RETR " + name );
1229
1228
getTransferSize ();
1230
- InputStream remote = createInputStream (s .getInputStream ());
1231
- byte [] buf = new byte [mtu * 10 ];
1232
- int l ;
1233
- while ((l = remote .read (buf )) >= 0 ) {
1234
- if (l > 0 ) {
1235
- local .write (buf , 0 , l );
1236
- }
1229
+ try (InputStream remote = createInputStream (s .getInputStream ())) {
1230
+ remote .transferTo (local );
1237
1231
}
1238
- remote .close ();
1239
1232
} else {
1240
1233
Socket s = openDataConnection ("RETR " + name );
1241
1234
getTransferSize ();
1242
- InputStream remote = createInputStream (s .getInputStream ());
1243
- byte [] buf = new byte [mtu * 10 ];
1244
- int l ;
1245
- while ((l = remote .read (buf )) >= 0 ) {
1246
- if (l > 0 ) {
1247
- local .write (buf , 0 , l );
1248
- }
1235
+ try (InputStream remote = createInputStream (s .getInputStream ())) {
1236
+ remote .transferTo (local );
1249
1237
}
1250
- remote .close ();
1251
1238
}
1252
1239
return completePending ();
1253
1240
}
@@ -1344,18 +1331,11 @@ public OutputStream putFileStream(String name, boolean unique)
1344
1331
*/
1345
1332
public sun .net .ftp .FtpClient putFile (String name , InputStream local , boolean unique ) throws sun .net .ftp .FtpProtocolException , IOException {
1346
1333
String cmd = unique ? "STOU " : "STOR " ;
1347
- int mtu = 1500 ;
1348
1334
if (type == TransferType .BINARY ) {
1349
1335
Socket s = openDataConnection (cmd + name );
1350
- OutputStream remote = createOutputStream (s .getOutputStream ());
1351
- byte [] buf = new byte [mtu * 10 ];
1352
- int l ;
1353
- while ((l = local .read (buf )) >= 0 ) {
1354
- if (l > 0 ) {
1355
- remote .write (buf , 0 , l );
1356
- }
1336
+ try (OutputStream remote = createOutputStream (s .getOutputStream ())) {
1337
+ local .transferTo (remote );
1357
1338
}
1358
- remote .close ();
1359
1339
}
1360
1340
return completePending ();
1361
1341
}
@@ -1373,17 +1353,10 @@ public sun.net.ftp.FtpClient putFile(String name, InputStream local, boolean uni
1373
1353
* @throws IOException if an error occurred during the transmission.
1374
1354
*/
1375
1355
public sun .net .ftp .FtpClient appendFile (String name , InputStream local ) throws sun .net .ftp .FtpProtocolException , IOException {
1376
- int mtu = 1500 ;
1377
1356
Socket s = openDataConnection ("APPE " + name );
1378
- OutputStream remote = createOutputStream (s .getOutputStream ());
1379
- byte [] buf = new byte [mtu * 10 ];
1380
- int l ;
1381
- while ((l = local .read (buf )) >= 0 ) {
1382
- if (l > 0 ) {
1383
- remote .write (buf , 0 , l );
1384
- }
1357
+ try (OutputStream remote = createOutputStream (s .getOutputStream ())) {
1358
+ local .transferTo (remote );
1385
1359
}
1386
- remote .close ();
1387
1360
return completePending ();
1388
1361
}
1389
1362
0 commit comments