Compare Java, JavApi, C#
Java JavApi C#
package javapi.samples.util.zip;

public class SampleGZIPOutputStream2File {

public static void main(String[] args) throws Exception {
String outFilename = "c:/temp/outfile.gzip";
java.util.zip.GZIPOutputStream out = new java.util.zip.GZIPOutputStream(new java.io.FileOutputStream(outFilename));

String inFilename = "c:/README.txt";
java.io.FileInputStream in = new java.io.FileInputStream(inFilename);

byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.finish();
out.close();
}
}
using System;

using java = biz.ritter.javapi;

namespace javapi.sample.util.zip
{
class SampleGZIPOutputStream2File
{
static void Main () {
String outFilename = "c:/temp/outfile.gzip";
java.util.zip.GZIPOutputStream outJ = new java.util.zip.GZIPOutputStream(new java.io.FileOutputStream(outFilename));

String inFilename = "c:/README.txt";
java.io.FileInputStream inJ = new java.io.FileInputStream(inFilename);

byte[] buf = new byte[1024];
int len;
while ((len = inJ.read(buf)) > 0) {
outJ.write(buf, 0, len);
}
inJ.close();
outJ.finish();
outJ.close();
}
}
}
using System;

 namespace javapi.sample.util.zip
{
class SampleGZIPOutputStream2FileCSharp
{
static void Main () {
String outFilename = "c:/temp/outfile.gzip";
System.IO.Compression.GZipStream outC = new System.IO.Compression.GZipStream (new System.IO.FileStream (outFilename, System.IO.FileMode.Create), System.IO.Compression.CompressionMode.Compress);

String inFilename = "c:/README.txt";
System.IO.FileStream inC = new System.IO.FileStream (inFilename, System.IO.FileMode.Open);

byte [] buf = new byte [1024];
int len;
while ((len = inC.Read(buf,0,buf.Length)) >0) {
outC.Write (buf,0,len);
}
inC.Close();
outC.Flush ();
outC.Close();
}
}
}

Last edited Feb 11, 2011 at 6:53 AM by bastie, version 2

Comments

No comments yet.