}
public InputCapture<? extends CapturePacket> newInput(final File file,
final Filter<ProtocolFilterTarget> filter) throws IOException {
final BufferedInputStream b =
new BufferedInputStream(new FileInputStream(file));
b.mark(1024); // Buffer first 1K of stream so we can rewind
/*
* Check the stream, without decompression first
*/
if (formatType(Channels.newChannel(b)) != null) {
b.close();
/*
* This is a plain uncompressed file, open up a FileChannel. It will be
* much faster
*/
return newInput(new RandomAccessFile(file, "rw").getChannel(), filter);
}
/*
* Try with gunziped stream, second
*/
b.reset(); // Rewind
if (formatType(Channels.newChannel(new GZIPInputStream(b))) != null) {
b.close();
/*
* Now reopen the same file, but this time without the buffered
* inputstream in the middle. Try to make things as efficient as possible.
* TODO: implement much faster channel based GZIP decompression algorithm
*/
return newInput(Channels.newChannel(new GZIPInputStream(
new FileInputStream(file))), filter);
}
b.close();
return factoryForOther.getFactory().newInput(
new RandomAccessFile(file, "r").getChannel(), filter);
}