File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Separate merged binary files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Separate merged binary files" Watch "Separate merged binary files" New topic
Author

Separate merged binary files

ravi D shankar
Ranch Hand

Joined: May 27, 2005
Posts: 41
Hey,

Can anyone please guide in separating 2 binary files using java api which got merged into 1 file.(appended one after the other). The file content is encoded in charset iso-8859-1.
Is there any standard way to separate individual binary files which were merged into one?

Thanks in advance,
Ravi
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

It's just reading the contents, and writing to one FileOutputStream first, then close it and write to another FileOutputStream next. The problem will be in finding where to split.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ravi D shankar
Ranch Hand

Joined: May 27, 2005
Posts: 41
Hi,

Can you give me some info on how I can identify where to split a merged binary file using java api?

Thanks in advance,
Ravi
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Well no, to be honest I can't. Like I said, that's the hard part.

What may also be important is to know what the file types should be; do you know? It may help in recognizing the headers inside the files.
Wentao Liang
Greenhorn

Joined: Oct 05, 2007
Posts: 13
I want to know that too.
ravi D shankar
Ranch Hand

Joined: May 27, 2005
Posts: 41
Hey,

The filetype I have is conventionally encrypted PGP/GnuPG file.
2 encrypted files have been merged into 1.
If the file format were to be ASCII, it would have been easy to separate them.
We are facing difficulties with the binary file.

Thanks
Ravi
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Well, let's just put Java aside for a moment.

Is this one particular file you're trying to recover the data from? And do you have the encryption key for the first file of the two? If so, here's what you do:

1) Run gpg to decrypt the combined file, supplying the key as needed. That will give you the first decrypted file. You'll get a warning about tampering because of the extra data but it will work.

2) Encrypt the first file using gpg again using the same key. Note the size of the file in bytes. That tells you the offset of the second file within the combined file!

3) Read the combined file in a Java program, skip that number of bytes from the beginning, and then write the rest to another file.

4) Decrypt that second file, if desired.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Separate merged binary files