Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Compressed data from XML file

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Location
    Hyrule
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Compressed data from XML file

    Hi everyone! I had a question about some data I'm extracting from an XML file. I'm pretty sure it's compressed, but I can't seem to decompress it using the InflaterInputStream method. I've been copying the text from the XML to actual .txt files so I could mess with it.

    I've tried 3 different methods of input:
    1. The straight text (which looks like hexidecimal)
    2. Binary
    3. Hexidecimal converted to text (which looks more normal for and encrypted file)
    When I run the first two with the Inflater method I get a "Unknown compression method" error. But with the last this does not occur, however the output file is blank.
    Samples of the 3 formats are below, as is some of the code I'm using. Any help would be appreciated.

    straight text as in XML:
    789cdd576d73e23610fe2b3bedcc4dae7324c604f2c2971a43 2e342150ec5ca633fe226c1974272c9f2c27a10cffbd2bd904 73716fd299bb36bd2f42c8dab76757fb48eb40aab819902463 411ef220a2716ce9919364deb45aaded3ca6fadf3a8845a2d4 8ce3c40ae2ec81655910870b2233aa7021959f6d702423bcbb d9ac835070217177379034b282b9a434b18219cfa9d5c5cfbf e0f23d7e86f56df229110f89114a396149a1bed9814049f110 e13827e9e2c4c209a7b16a9c58108494f3c756d3b68a59c73e 2e6767ad8e15a44446c108b42c5711ab0441b2a568bf984284 613750efb168319f4c6e3abc1f41ddc0dafaf87ce086e8cda2 f1ceb13456b649bc7f01b49c0b6ac36343bf86fe0f975e24e9 a2af057699d8ee9f8d62f6d1a570384c0780e9b2200230095e 848f431cf9464f385425ce69245f0ef01794142c6995ad544e 28f86939edd73bc815d0782cb59c2c21a39f7d2f5c007a75f8 bdd448a7b16515923e8f447c39ba1e74f1d7f8c19f4fef0fcc 1a8164a3d4231aeffbb4350c9e72e8a20e7e0e44ab84cd10c8 29905531a4b9a2d6804b3557d8cf06b7de9e9f85e5e349bd70 b8817ea7d2c991b40ee24538a26df178e2a0c7a08d379d36ed b3b3814999dd8565df830f2c04319f0a864b16e76a82896624 99227646cf056cb99e0e6abfd84dbdfa0550b5635250b21ff8 c44a8db6a61014c8be5e5bc885a3db63a6778f81f3bc7a7d61 6667b07f397006d3f42cd5eddc3049eaa257651ac509289042 e84840f2c63d856c92c124b96100e294a76e1493562c269a8b 0980ba183ec6d55aedcb7677d5f171cdcd087b7e08aa5369d1 522b5f1999ef98a8bda399abcb89cdbbb72b66dfbe4bb95f31 e2455c7d1ebb566b843e839ee95e35e0e8299090d5737eb4a3 a36ebf2c31ee7b4b69c53920bb2cc96664e8feb69a6ca32017 a07231ab11079db14cd3914d4058d093606e4206413f80013a 14896b17c09638905e39319a70aecb605cb393460f41e7ca70 7bd5bf71a7ec772b3611ae358c71125517cc320b60efb54491 2ae42f498c2a5cb0b575d926639a7d0b676bebacee4b9af453 923e8e37b2a31b3b43c4988888b45cb925cf7495f52620ee75 33e0aa13b22751fc544415fe67318268aa2371a55d87e2b44f e3f98583f2626dfa2b07f48605a6188fc1a53b5421295e8044 520de3fb68f4e7f8211cbf4a64338c07671e8e5293fecde88a 4a1fd47aad9ee6fc1f21a85e0118c54037ac33eb6dbe97b180 d3d177eb6f1da75d1424caf0630f4c1f36f27b8c1206b19685 be0292255f912b09a47cdf69169cf638997d3e7cbb67d6eb7b e960e2f5c08c1a12794e2f42b79c0887417a445465e9885d74 c837d96a502c95f17d50be910097077bb3bb13aff9c0ecb7b4 dcc1acdb655e138fd00c30b0ac9f08272c7d442e40aaed9922 9c33b596567f97ca855314c3ee672056f60c87942b36cf756d 1823742c19d909fb4254c64d4352b3da213bf5b73f1672e243 eac8c3646b37746eac897a8499f5a97e4191699aeee52b8b46 b1cabdecf5c4eb413e35ca5c5bb77df77ce9e45307833c2061 1d17dcfcfceec66130fcb20433ee6ccbc492a4a47e8d7129b1 35e7bef59480b231ba86466ff52cfe6092ae8ad4cda6bb28a9 b4c53d00e1e637fa84de87af7aaaead1663bdf214350b9bcd5 f2d4df6fa
    Not even gonna post binary its too long...

    XML version converted to "normal text":
    x?Wms6+;Ms$?C.4!P\3"lt',?,'+sqo? 6/BڷgWH@?$cA ql??d޴Z*<:?E?
    ?eY?"3p!??mp$#٬?Pp!qw7?4?4?ϩϿ=~?m )?J9aI?@I8' j?X??VӶ?Y>.gg*?DF,WAh?B?a7Ph1?Ln:A |?͢α4VI?jcC??^$颯v???bѥp8L? 0 ^??CFO8T%i$_?,i?*TN(i9;x,?,!?}/\?zuHe?>?D|9t?O?d#5?r~D?)?U1 ?K5WϷ???Ip?~?E8mx ?7?6?I??e?,1?
    ?Kj??f$?"vFl?jMPcRPJ?Ⱦ^[?cw??z}afg9p,0IWe (?BH@=?l?$a??n?V,&?? ?>Zvwq{~SiR+_????ͻ+f߾K_1E\} Vk?>??^5)??s~n,1{Ki9 ,fd?l r1?L?M@X?`nBA??:?k?8?^91?p`\?FAp{տqw+ 65?qU2`D?*/I?*\u&c?}gkK?S?>?7;C???\%t?& u3લ'QTDg1?h#q]?O??bm+??;T!)^?DR
    h!Jd3?g?R??Jz*?!^@73m??wo]$cL6{????%_?+ |i?8?}>|g{`?yN/B??AzDTe?]t7jP,?}P???{췴e^?0?',}D.@?"?3? V??Sg V??+6um#t, BTMCR!;?rCdk7tn?z??~A?i?+?FʽA >5\[}|S?< aa03l?~?q)5??1?Fo,`??ͦ( =?7??zf;!CPo
    Some code:
    		FileInputStream fis2 = new FileInputStream("original.txt");
    		InflaterInputStream iis = new InflaterInputStream(fis2);
    		FileOutputStream fos2 = new FileOutputStream("inflatedoriginal.txt");
    		System.out.println("start copying the output");
    		doCopy(iis, fos2); 
     
    	}
     
    	public static void doCopy(InputStream is, OutputStream os) throws Exception {
    		int oneByte;
    		while ((oneByte = is.read()) != -1) {
    			System.out.println(oneByte);
    			os.write(oneByte);
    		}
    Thanks again for any advice!
    Last edited by helloworld922; July 15th, 2010 at 03:38 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,286
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Compressed data from XML file

    What program generated your input file?
    Why do you think its XML? Is an XML file really a text file with special syntax?

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Location
    Hyrule
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Compressed data from XML file

    It's not so much the issue of it being an XML file, its more about the fact that the text is compressed and I can't seem to decompress it. When the InflaterInputStream runs on the second version, it doesn't fail but then there are no bytes when I try to print the result. It's the decompression that I'm stuck on, not extracting from the XML file.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,286
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Compressed data from XML file

    Yes, I understand.
    The question is how to get a text file from the file you have.

    What program generated your input file?
    Last edited by Norm; July 14th, 2010 at 08:30 PM.

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Location
    Hyrule
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Compressed data from XML file

    Actually, I'm a lot closer. The 789c tag at the beginning of the text indicates zlib compression, so using the java Inflate method should definitely work since that's what it is designed for. Now it's just a matter of getting my code to properly inflate the file. I converted the string to a BigInteger and then too a byte array, and printing the byte array shows that there is data there. However I am still getting the "Unknown compression method" error. Here's my code:
            BigInteger myint = new BigInteger("789cdd576d73e...",16);
    	byte[] mybytes = myint.toByteArray();
    	int arraylength = mybytes.length;
    	int i = 0;
     
    	while (i < arraylength){
    	System.out.println(mybytes[i]);
    	i++;
    	}
     
     
    	Inflater inf = new Inflater();
    	inf.setInput(mybytes, 0, arraylength);
    	byte[] result = new byte[5000];
    	inf.inflate(result);
    	int ResultLength = result.length;
    	inf.end();
     
    	String outputString = new String(result,0,ResultLength);
    	System.out.println(outputString);
    I feel like I must be really close, thanks for all the help!
    Last edited by helloworld922; July 15th, 2010 at 03:38 PM.

  6. #6
    Junior Member
    Join Date
    Jul 2010
    Location
    Hyrule
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Compressed data from XML file

    Haha epic fail, the previously posted code works, when I loaded the text and cleared the spaces, I accidentally deleted an extra value. Hence the unknown compression method because data was missing. Whew. This can be closed, but thanks for the input.

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Compressed data from XML file

    In the future, please surround your code with [highlight=Java]code goes here[/highlight]. It makes it much easier to read.

Similar Threads

  1. How to append data to an already existing file?
    By siteregsam in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 3rd, 2010, 03:31 PM
  2. Storing data from a socket to a file in real time
    By colossusdub in forum Java Networking
    Replies: 0
    Last Post: March 2nd, 2010, 09:10 AM
  3. Retrieving Meta-Data from a File
    By FretDancer69 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: February 9th, 2010, 08:10 AM
  4. Read data from text file
    By yroll in forum Algorithms & Recursion
    Replies: 4
    Last Post: December 31st, 2009, 01:40 AM
  5. Virutal File Directory from Given dAta
    By hugsheals in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: July 28th, 2009, 04:39 AM