* @throws IOException
*/
public void loadFile(File file, LoaderHandler handler, RDFFormat format, String compression) throws RDFParseException, IOException {
log.info("loading file {} ...", file);
CompressorStreamFactory cf = new CompressorStreamFactory();
cf.setDecompressConcatenated(true);
// detect the file compression
String detectedCompression = detectCompression(file);
if(compression == null) {
if(detectedCompression != null) {
log.info("using auto-detected compression ({})", detectedCompression);
compression = detectedCompression;
}
} else {
if(detectedCompression != null && !compression.equals(detectedCompression)) {
log.warn("user-specified compression ({}) overrides auto-detected compression ({})", compression, detectedCompression);
} else {
log.info("using user-specified compression ({})", compression);
}
}
// detect the file format
RDFFormat detectedFormat = Rio.getParserFormatForFileName(uncompressedName(file));
if(format == null) {
if(detectedFormat != null) {
log.info("using auto-detected format ({})", detectedFormat.getName());
format = detectedFormat;
} else {
throw new RDFParseException("could not detect input format of file "+ file);
}
} else {
if(detectedFormat != null && !format.equals(detectedFormat)) {
log.warn("user-specified format ({}) overrides auto-detected format ({})", format.getName(), detectedFormat.getName());
}
}
// create input stream from file and wrap in compressor stream
InputStream in;
InputStream fin = new BufferedInputStream(new FileInputStream(file));
try {
if(compression != null) {
if (CompressorStreamFactory.GZIP.equalsIgnoreCase(compression)) {
in = new GzipCompressorInputStream(fin,true);
} else if (CompressorStreamFactory.BZIP2.equalsIgnoreCase(compression)) {
in = new BZip2CompressorInputStream(fin, true);
} else {
// does not honour decompressConcatenated
in = cf.createCompressorInputStream(compression, fin);
}
} else {
in = cf.createCompressorInputStream(fin);
}
} catch (CompressorException ex) {
log.info("no compression detected, using plain input stream");
in = fin;
}