Search code examples
javafile-ioguava

How do I generate a Guava ByteSource from a Path?


I am trying to hash the file at a Path using Guava. I cannot use the File class because this is not supported by JimFS.

If I had a File, I would use this Guava method:

public static ByteSource asByteSource(File file)

Is there an equivalent for Path?

If not, how can I implement one?


Solution

  • If you only can use Path, then have a look at MoreFiles::asByteSource.