@@ -72,8 +72,8 @@ public final class FileAsyncRequestBody implements AsyncRequestBody {
7272 private final int chunkSizeInBytes ;
7373 private final long position ;
7474 private final long numBytesToRead ;
75- private final FileTime modifiedTimeAtStart ;
76- private final long sizeAtStart ;
75+ private FileTime modifiedTimeAtStart ;
76+ private Long sizeAtStart ;
7777
7878 private FileAsyncRequestBody (DefaultBuilder builder ) {
7979 this .path = builder .path ;
@@ -82,22 +82,25 @@ private FileAsyncRequestBody(DefaultBuilder builder) {
8282 this .position = builder .position == null ? 0 : Validate .isNotNegative (builder .position , "position" );
8383 this .numBytesToRead = builder .numBytesToRead == null ? fileLength - this .position :
8484 Validate .isNotNegative (builder .numBytesToRead , "numBytesToRead" );
85- try {
86- if ( builder .modifiedTimeAtStart != null ) {
87- this . modifiedTimeAtStart = builder . modifiedTimeAtStart ;
88- } else {
85+ if ( builder . modifiedTimeAtStart != null ) {
86+ this .modifiedTimeAtStart = builder . modifiedTimeAtStart ;
87+ } else {
88+ try {
8989 this .modifiedTimeAtStart = Files .getLastModifiedTime (path );
90+ } catch (IOException e ) {
91+ this .modifiedTimeAtStart = null ;
9092 }
93+ }
9194
92- if (builder .sizeAtStart != null ) {
93- this .sizeAtStart = builder .sizeAtStart ;
94- } else {
95+ if (builder .sizeAtStart != null ) {
96+ this .sizeAtStart = builder .sizeAtStart ;
97+ } else {
98+ try {
9599 this .sizeAtStart = Files .size (path );
100+ } catch (IOException e ) {
101+ this .sizeAtStart = null ;
96102 }
97- } catch (IOException e ) {
98- throw new RuntimeException (e );
99103 }
100-
101104 }
102105
103106 @ Override
@@ -135,7 +138,7 @@ public FileTime modifiedTimeAtStart() {
135138 return modifiedTimeAtStart ;
136139 }
137140
138- public long sizeAtStart () {
141+ public Long sizeAtStart () {
139142 return sizeAtStart ;
140143 }
141144
@@ -323,13 +326,22 @@ private final class FileSubscription implements Subscription {
323326
324327 private FileSubscription (AsynchronousFileChannel inputChannel ,
325328 Subscriber <? super ByteBuffer > subscriber ,
326- FileTime modifiedTimeAtStart , long sizeAtStart ) throws IOException {
329+ FileTime modifiedTimeAtStart , Long sizeAtStart ) throws IOException {
327330 this .inputChannel = inputChannel ;
328331 this .subscriber = subscriber ;
329- this .sizeAtStart = sizeAtStart ;
330- this .modifiedTimeAtStart = modifiedTimeAtStart ;
331332 this .remainingBytes = new AtomicLong (numBytesToRead );
332333 this .currentPosition = new AtomicLong (position );
334+ if (sizeAtStart != null ) {
335+ this .sizeAtStart = sizeAtStart ;
336+ } else {
337+ this .sizeAtStart = Files .size (path );
338+ }
339+
340+ if (modifiedTimeAtStart != null ) {
341+ this .modifiedTimeAtStart = modifiedTimeAtStart ;
342+ } else {
343+ this .modifiedTimeAtStart = Files .getLastModifiedTime (path );
344+ }
333345 }
334346
335347 @ Override
0 commit comments