This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compressing a string

 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

i'm hving some trouble with compressing (zipping) a String, i'm not too sure how to do t. i've seend examples of compressing a file but not a string, can anyone help me out

I'm trying to modeify this so it takes a string and not a file but getting no where, i know i have to use ByteArrayInputStream but don't know how to use in the example i have


String inFilename = "c:\articles\examplegzip.gz";
GZIPInputStream gzipInputStream =
new GZIPInputStream(new FileInputStream(inFilename));
// Open the output file
String outFilename = "c:\articles\statebirdsclone.txt";
OutputStream out = new FileOutputStream(outFilename);

// Transfer bytes from the compressed file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = gzipInputStream.read(buf)) > 0) {
out.write(buf, 0, len);
}

// Close the file and stream
gzipInputStream.close();
out.close();
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try with StringReader/ StringWriter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic