Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bennavapbc committed Nov 18, 2024
1 parent 554c4ee commit 34cde11
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions common/src/main/java/gov/cms/ab2d/common/GzipTesting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package gov.cms.ab2d.common;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GzipTesting {

static final int BUFFER_SIZE = 1024 * 4;

public static void main(String[] args) {
String originalFile = "/Users/benhesford/Downloads/ndjson-example-files/bigfile-copy.ndjson";
String gzippedFile = "/Users/benhesford/Downloads/ndjson-example-files/bigfile.ndjson.gz";

decompressGzipFile(gzippedFile, "/tmp/bigfile-decompressed-java.ndjson");

compressGzipFile(originalFile, "/tmp/bigfile-compressed-java.gz");


}

private static void decompressGzipFile(String gzipFile, String newFile) {
long now = System.currentTimeMillis();
try {
FileInputStream fis = new FileInputStream(gzipFile);
GZIPInputStream gis = new GZIPInputStream(fis);
FileOutputStream fos = new FileOutputStream(newFile);
byte[] buffer = new byte[BUFFER_SIZE];
int len;
while((len = gis.read(buffer)) != -1){
fos.write(buffer, 0, len);
}
//close resources
fos.close();
gis.close();
} catch (IOException e) {
e.printStackTrace();
}
long completed = System.currentTimeMillis();
System.out.println((completed-now)/1000.0 + " seconds to decompress");
}

private static void compressGzipFile(String file, String gzipFile) {
long now = System.currentTimeMillis();

try {
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(gzipFile);
GZIPOutputStream gzipOS = new GZIPOutputStream(fos) {
{
//def.setLevel(1);
}
};
byte[] buffer = new byte[BUFFER_SIZE];
int len;
while((len=fis.read(buffer)) != -1){
gzipOS.write(buffer, 0, len);
}
//close resources
gzipOS.close();
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
long completed = System.currentTimeMillis();
System.out.println((completed-now)/1000.0 + " seconds to compress");
}


}

0 comments on commit 34cde11

Please sign in to comment.