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.