@@ -43,17 +43,17 @@ public class ChronicleMapAdapter implements PopularityMap {
43
43
44
44
private ChronicleMap <BytesRef , Integer > map ;
45
45
46
- private final File f ;
46
+ private final File chronicleMapFile ;
47
47
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 )
49
49
throws IOException {
50
50
map = ChronicleMap .of (BytesRef .class , Integer .class )
51
51
.name (name )
52
52
.averageKeySize (averageKeySize )
53
53
.keyReaderAndDataAccess (BytesRefSizedReader .INSTANCE , new BytesRefDataAccess ())
54
54
.entries (entries )
55
- .createOrRecoverPersistedTo (f );
56
- this .f = f ;
55
+ .createOrRecoverPersistedTo (file );
56
+ this .chronicleMapFile = file ;
57
57
}
58
58
59
59
/** {@inheritDoc} */
@@ -120,26 +120,26 @@ public void resize(final int newMapSize, final double newMapAvgKey) throws IOExc
120
120
121
121
Path tempFile = Files .createTempFile ("opengrok" , "chronicle" );
122
122
123
- map .getAll (tempFile .toFile ());
123
+ try {
124
+ map .getAll (tempFile .toFile ());
124
125
125
- String field = map .name ();
126
+ String field = map .name ();
126
127
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 ();
139
129
140
- Files .delete (tempFile );
130
+ Files .delete (chronicleMapFile . toPath () );
141
131
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
+ }
143
143
}
144
144
145
145
/**
0 commit comments