can I consider File as a special case of InputStream and provide 1 API like
test(InputStream stream)
or two overloaded APIs are better
test(File f)
test(InputStream stream)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A file is certainly not an input stream. It can be used to create an input stream, but it’s not one itself.
Note that the overloads you’ve given have a fundamentally different character – the method accepting
Fileneedn’t change any state, but the method acceptingInputStreamalmost certainly would. Also, assuming they’re going to do something similar internally, theFilemethod would want to close the stream opened in the method; theInputStreammethod wouldn’t want to close the stream, because it doesn’t “own” it.That’s okay – it may well be fine to have these two methods anyway – but you need to be aware of the difference.
Another option is to use the Guava library and take an
InputSupplier<InputStream>– then callers can useFiles.newInputStreamSupplier(file)to specify the stream, but could also use a supplier of network-related input streams, etc.