Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

GZIPOutputStream and MemoryCacheImageOutputStream

Thread view: 
brechmos@gmail.com - 27 Sep 2005 16:26 GMT
I am working through some code I had written several years ago and am
sure that it worked then... I figured out my problem comes down to some
interaction with GZIPOutputStream and MemoryCacheImageOutputStream.  A
sample of code to show the problem is below...

If I comment out the MemoryCacheImageOutputStream and put in the
DataOutputStream it will work.

If I leave the MemoryCacheImageOutputStream and comment out the
GZIPOutputStream wrapper it will work.

Why does it not work with the MemoryCacheImageOutputStream and
GZIPOutputStream??

If I write out more data I watch a file in /tmp grow but when the
program finishes the file frank.txt.gz is still only 10 bytes (an empty
gzip?).

Any help would be appreciated!

import java.util.*;
import java.io.*;
import java.nio.*;
import java.util.zip.*;
import javax.imageio.stream.*;

public class Bob
{
   public static void main(String[] args)
   {
       OutputStream fos = null;
       String filename = "frank.txt.gz";

       try {
               fos = new FileOutputStream(new File(filename));
               if( filename.endsWith(".gz") )
                           { fos = new GZIPOutputStream( fos ); }
               fos = new BufferedOutputStream( fos );
       } catch (IOException e) {  System.out.println(e);
System.exit(0); }

       ImageOutputStream fcos = new MemoryCacheImageOutputStream(fos);
//      ImageOutputStream fcos = null; try { fcos = new
FileCacheImageOutputStream(fos, null);
} catch (Exception e) {}
//      DataOutputStream fcos = new DataOutputStream(fos);

       try {
           fcos.writeBytes("Here I am\n");
           fcos.close();
       }
       catch( Exception e)
       {
           System.out.println("could not write " + e);
System.exit(-1);
       }

   }

   public Bob()
       {
       }
}
Roedy Green - 27 Sep 2005 22:25 GMT
>If I write out more data I watch a file in /tmp grow but when the
>program finishes the file frank.txt.gz is still only 10 bytes (an empty
>gzip?).

I think you need more proof that than it did not work. Try reading the
file with the reverse program and see if you the back where you
started.

I am surprised DataOutputStream.writeBytes has not been deprecated.
For that sort of thing you really want a PrintWriter.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 27 Sep 2005 22:33 GMT
> fos = new FileOutputStream(new File(filename));

this is the naming convention used in the File IO Amanuensis. I have
wonder when I see people using it how that came to be:

1. convergent evolution to an obvious convention.

2. lots of people cut their teeth using
http://mindprod.com/applets/fileio.html

3. people copy others in a chain back to a file i/o amanuensis user.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Chris Uppal - 28 Sep 2005 09:15 GMT
>         try {
>             fcos.writeBytes("Here I am\n");
>             fcos.close();
>         }

The JavaDoc for MemoryCacheImageOutputStream.close() states that it does not
close() the underlying OutputStream (which is unexpected).  So you have to
close() that yourself before leaving the program.

   -- chris
Roedy Green - 28 Sep 2005 09:50 GMT
>The JavaDoc for MemoryCacheImageOutputStream.close() states that it does not
>close() the underlying OutputStream (which is unexpected).  So you have to
>close() that yourself before leaving the program.

Why would they do that?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.