|
16 | 16 | import net.lecousin.framework.concurrent.synch.SynchronizationPoint;
|
17 | 17 | import net.lecousin.framework.io.IO.AbstractIO;
|
18 | 18 | import net.lecousin.framework.io.IO.Seekable.SeekType;
|
19 |
| -import net.lecousin.framework.mutable.MutableInteger; |
20 | 19 | import net.lecousin.framework.mutable.MutableLong;
|
21 | 20 | import net.lecousin.framework.util.Pair;
|
22 | 21 | import net.lecousin.framework.util.RunnableWithParameter;
|
@@ -800,32 +799,24 @@ protected long getSizeSync() throws IOException {
|
800 | 799 | }
|
801 | 800 |
|
802 | 801 | protected AsyncWork<Long, IOException> getSizeAsync() {
|
| 802 | + @SuppressWarnings("unchecked") |
| 803 | + AsyncWork<Long, IOException>[] sizes = new AsyncWork[ios.size()]; |
| 804 | + for (int i = 0; i < ios.size(); ++i) |
| 805 | + sizes[i] = ((IO.KnownSize)ios.get(i)).getSizeAsync(); |
| 806 | + JoinPoint<IOException> jp = JoinPoint.fromSynchronizationPointsSimilarError(sizes); |
803 | 807 | AsyncWork<Long, IOException> result = new AsyncWork<Long, IOException>();
|
804 |
| - MutableLong total = new MutableLong(0); |
805 |
| - MutableInteger index = new MutableInteger(0); |
806 |
| - ((IO.KnownSize)ios.get(0)).getSizeAsync().listenInline(new AsyncWorkListener<Long, IOException>() { |
807 |
| - @Override |
808 |
| - public void ready(Long size) { |
809 |
| - total.add(size.longValue()); |
810 |
| - if (index.inc() == ios.size()) |
811 |
| - result.unblockSuccess(Long.valueOf(total.get())); |
812 |
| - else |
813 |
| - ((IO.KnownSize)ios.get(index.get())).getSizeAsync().listenInline(this); |
814 |
| - } |
815 |
| - |
816 |
| - @Override |
817 |
| - public void error(IOException error) { |
818 |
| - result.unblockError(error); |
819 |
| - } |
820 |
| - |
821 |
| - @Override |
822 |
| - public void cancelled(CancelException event) { |
823 |
| - result.unblockCancel(event); |
824 |
| - } |
825 |
| - }); |
| 808 | + jp.listenInline( |
| 809 | + () -> { |
| 810 | + long total = 0; |
| 811 | + for (int i = 0; i < sizes.length; ++i) |
| 812 | + total += sizes[i].getResult().longValue(); |
| 813 | + result.unblockSuccess(Long.valueOf(total)); |
| 814 | + }, |
| 815 | + result |
| 816 | + ); |
826 | 817 | return result;
|
827 | 818 | }
|
828 |
| - |
| 819 | + |
829 | 820 |
|
830 | 821 | protected long getPosition() {
|
831 | 822 | return pos;
|
|
0 commit comments