2828import java .nio .channels .ReadableByteChannel ;
2929import java .nio .charset .StandardCharsets ;
3030import java .nio .file .Files ;
31+ import java .nio .file .Path ;
3132import java .util .Collections ;
3233import java .util .List ;
3334import java .util .Map ;
3435
3536public class FileBody implements Body {
36- private File file ;
37+ private Path file ;
3738
38- public FileBody (File file ) {
39+ public FileBody (Path file ) {
3940 this .file = file ;
4041 }
4142
4243 @ Override public long length () {
43- return file .length ();
44+ try {
45+ return Files .size (file );
46+ } catch (IOException x ) {
47+ throw Throwing .sneakyThrow (x );
48+ }
4449 }
4550
4651 @ Override public boolean isInMemory () {
@@ -49,23 +54,23 @@ public FileBody(File file) {
4954
5055 @ Override public ReadableByteChannel channel () {
5156 try {
52- return Files .newByteChannel (file . toPath () );
57+ return Files .newByteChannel (file );
5358 } catch (IOException x ) {
5459 throw Throwing .sneakyThrow (x );
5560 }
5661 }
5762
5863 @ Override public InputStream stream () {
5964 try {
60- return new FileInputStream (file );
65+ return Files . newInputStream (file );
6166 } catch (IOException x ) {
6267 throw Throwing .sneakyThrow (x );
6368 }
6469 }
6570
6671 @ Override public byte [] bytes () {
6772 try {
68- return Files .readAllBytes (file . toPath () );
73+ return Files .readAllBytes (file );
6974 } catch (IOException x ) {
7075 throw Throwing .sneakyThrow (x );
7176 }
0 commit comments