B
brechmos
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()
{
}
}
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()
{
}
}