Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/mcl/net/MapiSocket.java @ 547:8029d7368b5a onclient
Make sure the download stream isn't closed twice
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Tue, 14 Sep 2021 09:23:03 +0200 (2021-09-14) |
parents | 31df6a12fd41 |
children | 7b320303b579 |
comparison
equal
deleted
inserted
replaced
546:eb7ecfbb48f2 | 547:8029d7368b5a |
---|---|
1364 public static class DownloadStream extends InputStream { | 1364 public static class DownloadStream extends InputStream { |
1365 | 1365 |
1366 private final BlockInputStream.Raw rawIn; | 1366 private final BlockInputStream.Raw rawIn; |
1367 private final OutputStream out; | 1367 private final OutputStream out; |
1368 private boolean endBlockSeen = false; | 1368 private boolean endBlockSeen = false; |
1369 private boolean closed = false; | |
1369 | 1370 |
1370 DownloadStream(BlockInputStream.Raw rawIn, OutputStream out) { | 1371 DownloadStream(BlockInputStream.Raw rawIn, OutputStream out) { |
1371 this.rawIn = rawIn; | 1372 this.rawIn = rawIn; |
1372 this.out = out; | 1373 this.out = out; |
1373 } | 1374 } |
1374 | 1375 |
1375 void nextBlock() throws IOException { | 1376 void nextBlock() throws IOException { |
1376 if (endBlockSeen) | 1377 if (endBlockSeen || closed) |
1377 return; | 1378 return; |
1378 int ret = rawIn.readBlock(); | 1379 int ret = rawIn.readBlock(); |
1379 if (ret < 0 || rawIn.wasEndBlock()) { | 1380 if (ret < 0 || rawIn.wasEndBlock()) { |
1380 endBlockSeen = true; | 1381 endBlockSeen = true; |
1381 } | 1382 } |
1382 } | 1383 } |
1383 | 1384 |
1384 @Override | 1385 @Override |
1385 public void close() throws IOException { | 1386 public void close() throws IOException { |
1387 if (closed) | |
1388 return; | |
1389 closed = true; | |
1386 while (!endBlockSeen) { | 1390 while (!endBlockSeen) { |
1387 nextBlock(); | 1391 nextBlock(); |
1388 } | 1392 } |
1389 // Send acknowledgement to server | 1393 // Send acknowledgement to server |
1390 out.write('\n'); | 1394 out.write('\n'); |
1391 out.flush(); | 1395 out.flush(); |
1392 // And await the acknowledgement of the acknowledgement | |
1393 // Do whatever super has to do | 1396 // Do whatever super has to do |
1394 super.close(); | 1397 super.close(); |
1395 } | 1398 } |
1396 | 1399 |
1397 @Override | 1400 @Override |