Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Last active December 12, 2015 04:38
Show Gist options
  • Save TrevorS/4715590 to your computer and use it in GitHub Desktop.
Save TrevorS/4715590 to your computer and use it in GitHub Desktop.
GZIP Example
/**
* Parse a CIBER file.
* @param file the compressed or uncompressed CIBER file
*/
public void parseFile(File file) {
// Clear the record list.
clearTransaction();
// Set the current file name.
currentFileName = file.getName();
try {
BufferedInputStream stream;
// Get the counters ready for the new file.
counters.newFile(file);
// If the file ends with ".gz" it should be decompressed.
if (file.getName().endsWith(".gz")) {
LogMF.debug(logger, "detected gziped file.", null);
if (validator.isFileValid(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))))) {
stream = new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)));
//Parse the file stream.
parseStream(stream);
}
else {
LogMF.error(logger, "Invalid file: {0}", new Object[]{ currentFileName });
}
}
// If not, we should act like it's a regular file.
else {
LogMF.debug(logger, "detected regular file.", null);
if (validator.isFileValid(new BufferedInputStream(new FileInputStream(file)))) {
stream = new BufferedInputStream(new FileInputStream(file));
//Parse the file stream.
parseStream(stream);
}
else {
LogMF.error(logger, "Invalid file: {0}", new Object[]{ currentFileName });
}
}
// Save our counter results.
counters.saveFileCounters();
}
catch (FileNotFoundException e) {
LogMF.error(logger, "Could not locate file: {0}", new Object[]{ file });
}
catch (IOException e) {
LogMF.error(logger, "Error loading file: {0}", new Object[]{ file });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment