This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes SequenceInputStream issue . it cant read all the streams in it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "SequenceInputStream issue . it cant read all the streams in it" Watch "SequenceInputStream issue . it cant read all the streams in it" New topic
Author

SequenceInputStream issue . it cant read all the streams in it

anas alsarairah
Greenhorn

Joined: Sep 27, 2007
Posts: 28
hello
i have an application that receives a list of PDF streams and then and then tries to merge them together into one single stream using SequenceInputStream class but the problem when i try to write the SequenceInputStream it doesnt write all the expected streams that have been included in the SequenceInputStream .... and please see the code beneath



please anyone help me on this
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

1. When posting code, please UseCodeTags(⇐click) so it will be readable.

2. How are you determining that it's "not working"? That is, what is the exact behavior that you are observing?

3. I don't think this even can work. I don't think you can create a valid PDF file by concatenating together other PDF files. Just because it works for text files doesn't mean it will work for other formats, and in fact, for the vast majority of other formats, it won't work.
anas alsarairah
Greenhorn

Joined: Sep 27, 2007
Posts: 28
hello
tanks for your reply
well what i do is that i create a list with 2 input streams and then i create a sequence input stream object from the list then i start writing the sequence to a single output file ... now the problem is that only the last file gets written to the output file and the first one somehow disappear

thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

anas alsarairah wrote:hello
tanks for your reply
well what i do is that i create a list with 2 input streams and then i create a sequence input stream object from the list then i start writing the sequence to a single output file


Yes, that much was clear from the original post. As I said in my previous reply, I don't think that's can produce a valid file with PDF.

... now the problem is that only the last file gets written to the output file and the first one somehow disappear


How exactly are you determining this? What exact steps are you taking and what's the exact behavior you're seeing? I can't help you with your code until I read it, and I won't read it if you don't UseCodeTags(⇐click) to format it properly.

My advice is this: First get it working with plain text files:



We know this technique can work with text files. We don't know that it can work with PDFs. Once you get it working with text files, then try it with your PDFs. If you're still having a problem, then, as I suspected, it's not possible with PDFs.
anas alsarairah
Greenhorn

Joined: Sep 27, 2007
Posts: 28
ok ... now i have used code tags if you would like to have a look ... but my question now how can i do that i mean how can i merg pdf streams ... whats the best way please

thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

anas alsarairah wrote:ok ... now i have used code tags if you would like to have a look


First try it with text files. If you can't get that to work, post that code and provide details of what's going wrong.

how can i merg pdf streams


If I'm correct and this approach can't work, then you won't be "merging streams." You'll be combining documents.

You'll have to either read up on the PDF format and build a tool that can parse the existing PDFs and combine them into one, or you'll have to find a library that can read PDFs and a library that can write PDFs (may or may not be the same library), use those to bring the PDFs into an object model, combine that object model into a single document, and write it out. I know iText can be used for writing PDFs. Don't know if it can read them.
anas alsarairah
Greenhorn

Joined: Sep 27, 2007
Posts: 28
well yes i tried it and its working for text files

i wrote in the first text file (anas )and in the second one (alsarairah )
and the resultant file had the following (anasalsarairah)
which combines the content of the text files

thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

anas alsarairah wrote:well yes i tried it and its working for text files


Then clearly this approach is not valid for PDF, so you'll need something that can parse them, for starters.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SequenceInputStream issue . it cant read all the streams in it
 
Similar Threads
Comparint contents of 2 files in different folders
Merging byte arrays using SequenceInputStream
SequenceInputStream issue . it cant read all the streams in it
Issue w/ accesing file from a Servlet
Problem in setBinaryStream when using SequenceInputStream