Commit 8178f48
authored
Fix inconsistent exception in
The implementation of `IOUtils.toByteArray(InputStream, int, int)` added in #776 throws different exceptions depending on the requested size:
* For request sizes larger than the internal chunk size, it correctly throws an `EOFException`.
* For smaller requests, it incorrectly throws a generic `IOException`.
This PR makes the behavior consistent by always throwing an `EOFException` when the stream ends prematurely.
Note: This also affects `RandomAccessFiles.read`. Its previous truncation behavior was undocumented and inconsistent with `RandomAccessFile.read` (which reads as much as possible). The new behavior is not explicitly documented here either, since it is unclear whether throwing on truncation is actually desirable.IOUtils.toByteArray (#796)1 parent 45578a7 commit 8178f48
File tree
2 files changed
+12
-2
lines changed- src
- main/java/org/apache/commons/io
- test/java/org/apache/commons/io
2 files changed
+12
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2941 | 2941 | | |
2942 | 2942 | | |
2943 | 2943 | | |
| 2944 | + | |
2944 | 2945 | | |
2945 | 2946 | | |
2946 | 2947 | | |
| |||
2958 | 2959 | | |
2959 | 2960 | | |
2960 | 2961 | | |
2961 | | - | |
| 2962 | + | |
2962 | 2963 | | |
2963 | 2964 | | |
2964 | 2965 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
| |||
1788 | 1790 | | |
1789 | 1791 | | |
1790 | 1792 | | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
1791 | 1800 | | |
1792 | 1801 | | |
1793 | 1802 | | |
| |||
0 commit comments