{
File indexDir = File.createTempFile( remoteIndexFile, ".dir" );
indexDir.delete();
indexDir.mkdirs();
FSDirectory directory = FSDirectory.open( indexDir );
BufferedInputStream is = null;
try
{
is = new BufferedInputStream( fetcher.retrieve( remoteIndexFile ) );
Date timestamp = null;
if ( remoteIndexFile.endsWith( ".gz" ) )
{
timestamp = unpackIndexData( is, directory, //
updateRequest.getIndexingContext() );
}
else
{
// legacy transfer format
timestamp = unpackIndexArchive( is, directory, //
updateRequest.getIndexingContext() );
}
if ( updateRequest.getDocumentFilter() != null )
{
filterDirectory( directory, updateRequest.getDocumentFilter() );
}
if ( merge )
{
updateRequest.getIndexingContext().merge( directory );
}
else
{
updateRequest.getIndexingContext().replace( directory );
}
if ( sideEffects != null && sideEffects.size() > 0 )
{
getLogger().info( IndexUpdateSideEffect.class.getName() + " extensions found: " + sideEffects.size() );
for ( IndexUpdateSideEffect sideeffect : sideEffects )
{
sideeffect.updateIndex( directory, updateRequest.getIndexingContext(), merge );
}
}
return timestamp;
}
finally
{
IOUtil.close( is );
if ( directory != null )
{
directory.close();
}
try
{
FileUtils.deleteDirectory( indexDir );