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 5 of 5

Thread: ZipEntry to InputStream or java.io.File. How?

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    21
    My Mood
    Sleepy
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question ZipEntry to InputStream or java.io.File. How?

    Hi,
    I've spent many hours trying to find a solution to this problem, but all in vain.
    Here's the deal:
    I have a ZipInputStream, which I've even managed to get a ZipEntry from.
    I can get the size or the name of this entry. The entry itself is an XML file which I need to get access to,
    but how can I do that without a ZipFile instance?

    Here's my code so far:
    ByteArrayInputStream    bais           = new ByteArrayInputStream(zipBytes);     
     ZipInputStream            zis            = new ZipInputStream(bais);
    ZipEntry                      ze             = zis.getNextEntry();
    I need to extract the entry as InputStream or java.io.File to pass it to a DocumentBuilder and parse the XML.
    Any ideas?

    thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: ZipEntry to InputStream or java.io.File. How?

    After you get the ZipEntry have you tried reading from the ZipInputStream to read its data?
    Read the API doc for the getNextEntry() method.

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    21
    My Mood
    Sleepy
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: ZipEntry to InputStream or java.io.File. How?

    Yeah, I did it..
    I seem to have found the problem, it's my overtiredness. I forgot the XML file is XOR encrypted, that's why it can't read it

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    21
    My Mood
    Sleepy
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: ZipEntry to InputStream or java.io.File. How?

    Well, I was wrong, the encryption was not a problem.
    I cannot even get the size of the entry. It always returns -1.
    I've managed to google out that it's because the size is written after the entry.
    Like I can easily get it from ZipFile, but the problem is that I don't have a zip file, I only have a ZipInputStream..
    It there any workaround to it?
    Last edited by goodguy; November 27th, 2011 at 04:21 AM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: ZipEntry to InputStream or java.io.File. How?

    For testing try creating a zip file in a byte array and then getting a ZipInputStream on that and reading from it. Then post the code here if you can't get it to work.

Similar Threads

  1. 1 packet delay with inputstream
    By tobi06 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 27th, 2011, 04:53 AM
  2. [SOLVED] Class loader , InputStream-AudioStream (method) , returns an AudioStream Objet
    By chronoz13 in forum File I/O & Other I/O Streams
    Replies: 14
    Last Post: July 9th, 2011, 11:14 AM
  3. Looping an inputstream
    By Trunk Monkeey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 02:39 PM
  4. [SOLVED] InputStream to File
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: May 2nd, 2011, 01:05 PM
  5. InputStream Problem at Client Side
    By pavan in forum Web Frameworks
    Replies: 1
    Last Post: March 26th, 2010, 03:21 AM