Question

I'm successfully using VFS to download files from HTTP, SFTP, FTP, etc. I need to get the content type of the file and I've run into a strange thing that I'm not sure why is happening.

FileObject file = vfs.resolveFile(uri) ;
FileContent content = remote.getContent();

InputStream source = content.getInputStream();
ByteArrayOutputStream target = new ByteArrayOutputStream();
copy(source, target);

content.getSize(); // HACK: Prevents null-pointer in next line
String type = content.getContentInfo().getContentType();

If I remove the call to getSize, content.getContentInfo will return null. Why is this? Am I missing something?

Was it helpful?

Solution

As @Sam-Rad wrote, it is fixed in trunk (upcoming VFS 2.1):

https://issues.apache.org/jira/browse/VFS-427

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top