I guess the difference is of Reader and Inputstream. In your example, a PDF doc is binary data which should not be transferred character by character but byte by byte. Check this link in the same forum for more on Reader and InputStream. Even though it mentioned wrapping of Stream by Reader, as mentioned earlier for binary data this should be discouraged.
EDIT: 1
Lets check the way Reader and InputStream's read method works
Reader.read()
returns integer in the range 0 to 65535 (single 16-bit Unicode character)
InputStream.read()
returns byte (8-bit signed two's complement integer) of data
Now imagine if you use Reader to read binary data (which is sequence of 8 bit integer), you will end up reading two bytes (8*2) instead of one assuming it to be a character.
I have not seen the code for PdfReader
so not sure if it uses java.io.Reader
. This explaination is purly for java.io.Reader/InputStream
. I would appreciate if you share some link or post which which says the the PdfReader
if used in a manner you mentioned, is not good.
EDIT:2
Remember:
- From a network, you can read the stream bytes only once.
- If you need those bytes for multiple tasks, better store those bytes in array and used the same array multiple time
If you use
PdfReader localPdfReader = new PdfReader(item.getinputStream());
then PdfReader internally reads the bytes from stream and uses it to validate. It does not store it for any further usage.
If you use
IOUtils
It copies the bytes from network to a byte array which later can be used in PdfReader
as well as JDBC call to store it in DB.