• Post Reply Bookmark Topic Watch Topic
  • New Topic

SequenceInputStream not reading the second file  RSS feed

 
Frederik Ericsson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

I want to ask your help since you might have gone through this before. I tried the SequenceInputStream, unfortunately it's not reading the second file, the result file shows only the XYZ file only, it didnt really add the other one. Please help me out on finding what I might have missed in this?


Vector files = new Vector();
FileInputStream f1 = new FileInputStream("C:\\FileNet\\XYZ.pdf");
FileInputStream f2 = new FileInputStream("C:\\FileNet\\documents\\ABC.pdf");
files.add(f1);
files.add(f2);
Enumeration enu = files.elements();
FileOutputStream fostream = new FileOutputStream("Result.pdf");
//InputStreamEnumerator e = new InputStreamEnumerator(files);
InputStream input = new SequenceInputStream(enu);
fostream.write(IOUtils.toByteArray(input));
input.close();
fostream.close();

Please let me know if you need more information on this.

Thanks
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect it is concatenating the two files, but your PDF viewer doesn't know it should look for a second file after the end of the data for the first one. I'm not really familiar with PDF's internal format, but it may not support simple concatenation like that. To test this theory, take a look at the files sizes of the two input files and one output file. Is the output size equal to the sum of the input sizes?
 
Frederik Ericsson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No worries, I got the answers from the previous posts, this may not work for all document/image formats, works well with .txt, I need to use something different. file1 size is equal to output file size.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:I'm not really familiar with PDF's internal format, but it may not support simple concatenation like that.


It doesn't.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!