Skip to content

Commit 9c4f072

Browse files
committed
improving read performance for compressed files (Z, zip, bz2, gzip, gz) by 300%
1 parent 401f239 commit 9c4f072

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cdm/core/src/main/java/ucar/nc2/NetcdfFile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,15 @@ private static String makeUncompressed(String filename) throws IOException {
631631

632632
try {
633633
if (suffix.equalsIgnoreCase("Z")) {
634-
try (InputStream in = new UncompressInputStream(new FileInputStream(filename))) {
634+
try (InputStream in = new UncompressInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
635635
copy(in, fout, 100000);
636636
}
637637
if (debugCompress)
638638
log.info("uncompressed {} to {}", filename, uncompressedFile);
639639

640640
} else if (suffix.equalsIgnoreCase("zip")) {
641641

642-
try (ZipInputStream zin = new ZipInputStream(new FileInputStream(filename))) {
642+
try (ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
643643
ZipEntry ze = zin.getNextEntry();
644644
if (ze != null) {
645645
copy(zin, fout, 100000);
@@ -649,15 +649,15 @@ private static String makeUncompressed(String filename) throws IOException {
649649
}
650650

651651
} else if (suffix.equalsIgnoreCase("bz2")) {
652-
try (InputStream in = new CBZip2InputStream(new FileInputStream(filename), true)) {
652+
try (InputStream in = new CBZip2InputStream(new BufferedInputStream(new FileInputStream(filename)), true)) {
653653
copy(in, fout, 100000);
654654
}
655655
if (debugCompress)
656656
log.info("unbzipped {} to {}", filename, uncompressedFile);
657657

658658
} else if (suffix.equalsIgnoreCase("gzip") || suffix.equalsIgnoreCase("gz")) {
659659

660-
try (InputStream in = new GZIPInputStream(new FileInputStream(filename))) {
660+
try (InputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
661661
copy(in, fout, 100000);
662662
}
663663

cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private static String makeUncompressed(String filename) throws Exception {
575575
try {
576576
if (suffix.equalsIgnoreCase("Z")) {
577577
// Z file can only contain one file - copy the whole thing
578-
try (InputStream in = new UncompressInputStream(new FileInputStream(baseFilename))) {
578+
try (InputStream in = new UncompressInputStream(new BufferedInputStream(new FileInputStream(baseFilename)))) {
579579
copy(in, fout, 100000);
580580
}
581581
if (NetcdfFile.debugCompress) {
@@ -584,7 +584,7 @@ private static String makeUncompressed(String filename) throws Exception {
584584

585585
} else if (suffix.equalsIgnoreCase("zip")) {
586586
// find specified zip entry, if it exists
587-
try (ZipInputStream zin = new ZipInputStream(new FileInputStream(baseFilename))) {
587+
try (ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(baseFilename)))) {
588588
// If a desired zipentry ID was appended to method's filename parameter, then itempath
589589
// is of length > 1 and ID starts at itempath char offset 1.
590590
String itemName = (itempath.length() > 1) ? itempath.substring(1) : "";
@@ -606,15 +606,15 @@ private static String makeUncompressed(String filename) throws Exception {
606606

607607
} else if (suffix.equalsIgnoreCase("bz2")) {
608608
// bz2 can only contain one file - copy the whole thing
609-
try (InputStream in = new CBZip2InputStream(new FileInputStream(baseFilename), true)) {
609+
try (InputStream in = new CBZip2InputStream(new BufferedInputStream(new FileInputStream(baseFilename)), true)) {
610610
copy(in, fout, 100000);
611611
}
612612
if (NetcdfFile.debugCompress)
613613
log.info("unbzipped {} to {}", filename, uncompressedFile);
614614

615615
} else if (suffix.equalsIgnoreCase("gzip") || suffix.equalsIgnoreCase("gz")) {
616616
// gzip/gz concatenates streams - copy the whole thing
617-
try (InputStream in = new GZIPInputStream(new FileInputStream(baseFilename))) {
617+
try (InputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(baseFilename)))) {
618618
copy(in, fout, 100000);
619619
}
620620

0 commit comments

Comments
 (0)