@@ -43,17 +43,17 @@ public class ChronicleMapAdapter implements PopularityMap {
4343
4444 private ChronicleMap <BytesRef , Integer > map ;
4545
46- private final File f ;
46+ private final File chronicleMapFile ;
4747
48- public ChronicleMapAdapter (final String name , final double averageKeySize , final int entries , final File f )
48+ public ChronicleMapAdapter (final String name , final double averageKeySize , final int entries , final File file )
4949 throws IOException {
5050 map = ChronicleMap .of (BytesRef .class , Integer .class )
5151 .name (name )
5252 .averageKeySize (averageKeySize )
5353 .keyReaderAndDataAccess (BytesRefSizedReader .INSTANCE , new BytesRefDataAccess ())
5454 .entries (entries )
55- .createOrRecoverPersistedTo (f );
56- this .f = f ;
55+ .createOrRecoverPersistedTo (file );
56+ this .chronicleMapFile = file ;
5757 }
5858
5959 /** {@inheritDoc} */
@@ -120,26 +120,26 @@ public void resize(final int newMapSize, final double newMapAvgKey) throws IOExc
120120
121121 Path tempFile = Files .createTempFile ("opengrok" , "chronicle" );
122122
123- map .getAll (tempFile .toFile ());
123+ try {
124+ map .getAll (tempFile .toFile ());
124125
125- String field = map .name ();
126+ String field = map .name ();
126127
127- map .close ();
128-
129- Files .delete (f .toPath ());
130-
131- ChronicleMap <BytesRef , Integer > m = ChronicleMap .of (BytesRef .class , Integer .class )
132- .name (field )
133- .averageKeySize (newMapAvgKey )
134- .entries (newMapSize )
135- .keyReaderAndDataAccess (BytesRefSizedReader .INSTANCE , new BytesRefDataAccess ())
136- .createOrRecoverPersistedTo (f );
137-
138- m .putAll (tempFile .toFile ());
128+ map .close ();
139129
140- Files .delete (tempFile );
130+ Files .delete (chronicleMapFile . toPath () );
141131
142- map = m ;
132+ ChronicleMap <BytesRef , Integer > m = ChronicleMap .of (BytesRef .class , Integer .class )
133+ .name (field )
134+ .averageKeySize (newMapAvgKey )
135+ .entries (newMapSize )
136+ .keyReaderAndDataAccess (BytesRefSizedReader .INSTANCE , new BytesRefDataAccess ())
137+ .createOrRecoverPersistedTo (chronicleMapFile );
138+ m .putAll (tempFile .toFile ());
139+ map = m ;
140+ } finally {
141+ Files .delete (tempFile );
142+ }
143143 }
144144
145145 /**
0 commit comments