FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   save in compressed .gz format
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: save in compressed .gz format  (Read 320 times)
marcello

WWW Email
save in compressed .gz format
« on: Jul 25th, 2004, 10:36am »

Is it possible to save text files in .gz compressed format using p5?
 
Marcello
« Last Edit: Jul 25th, 2004, 11:05am by marcello »  
narain


Re: save in compressed .gz format
« Reply #1 on: Jul 25th, 2004, 11:52am »

There's java.util.zip.GZIPOutputStream that's part of Java 1.3, and there's a tutorial on it at http://www.devshed.com/c/a/Java/GZIPping-with-Java/2/
 
But that may be more trouble than it's worth...
How badly do you need to do GZip?
« Last Edit: Jul 25th, 2004, 11:54am by narain »  
fry


WWW
Re: save in compressed .gz format
« Reply #2 on: Jul 25th, 2004, 6:04pm »

gzip is in java 1.1 as well, so something like this should work:  (untested..)
 
Code:
try {
  public void saveStrings(String filename, String strings[]) {
    FileOutputStream fos = new FileOutputStream(filename);
    GZIPOutputStream output = new GZIPOutputStream(fos);
    PrintWriter writer =  
 new PrintWriter(new OutputStreamWriter(output));
    for (int i = 0; i < strings.length; i++) {
 writer.println(strings[i]);
    }
    writer.flush();
  }
} catch (Exception e) {
  e.printStackTrace();
}
 
marcello

WWW Email
Re: save in compressed .gz format
« Reply #3 on: Jul 25th, 2004, 6:23pm »

narain and fry,
Thank you very much for your inputs. I'll tell you here if I'll be able to get a good return on your suggestions.
 
narain,
Together with a bunch of friends I'm working to an application that should allow users to store txt files on a server. These txt files contain the code of 3d virtual creatures in the style of sodaplay (look at my homepage). Now the problem is that those data could take a lot of space so the best thing is to save these files in compressed format.
 
Best Regards,
Marcello
 
marcello

WWW Email
Re: save in compressed .gz format
« Reply #4 on: Jul 25th, 2004, 8:24pm »

Ok! With just few modifies i was able to make work the fry's code. Here is the tested code:
 
Code:
String [] file;
 
void setup() {
  file = new String [100];
  for (int i=0; i<100; i++) {
    file[i]="thank you very mutch guys ;)";  
  }
    saveStrings("thanks.txt.gz",file);
}
 
public void saveStrings(String filename, String strings[]) {  
  try {  
    FileOutputStream fos = new FileOutputStream(filename);  
    GZIPOutputStream output = new GZIPOutputStream(fos);  
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(output));  
    for (int i = 0; i < strings.length; i++) {  
      writer.println(strings[i]);  
    }  
    writer.flush();  
    writer.close();
  }
  catch (Exception e) {  
    e.printStackTrace();  
  }  
}

 
Thank you very much again,
Marcello
« Last Edit: Jul 25th, 2004, 8:28pm by marcello »  
Pages: 1 

« Previous topic | Next topic »