|
12 | 12 | import org.elasticsearch.TransportVersion;
|
13 | 13 | import org.elasticsearch.common.bytes.BytesReference;
|
14 | 14 | import org.elasticsearch.common.bytes.ReleasableBytesReference;
|
| 15 | +import org.elasticsearch.core.Nullable; |
15 | 16 | import org.elasticsearch.core.Releasable;
|
16 | 17 |
|
17 | 18 | import java.io.IOException;
|
@@ -231,16 +232,24 @@ private static <T> T deserialize(
|
231 | 232 | NamedWriteableRegistry registry,
|
232 | 233 | BytesReference serialized
|
233 | 234 | ) throws IOException {
|
234 |
| - try ( |
235 |
| - StreamInput in = registry == null |
236 |
| - ? new DeduplicateStreamInput(serialized.streamInput(), new DeduplicatorCache()) |
237 |
| - : new DeduplicateNamedWriteableAwareStreamInput(serialized.streamInput(), registry, new DeduplicatorCache()) |
238 |
| - ) { |
239 |
| - in.setTransportVersion(serializedAtVersion); |
240 |
| - return reader.read(in); |
| 235 | + try (StreamInput in = serialized.streamInput()) { |
| 236 | + return reader.read(wrapWithDeduplicatorStreamInput(in, serializedAtVersion, registry)); |
241 | 237 | }
|
242 | 238 | }
|
243 | 239 |
|
| 240 | + /** Wraps the provided {@link StreamInput} with another stream that extends {@link Deduplicator} */ |
| 241 | + public static StreamInput wrapWithDeduplicatorStreamInput( |
| 242 | + StreamInput in, |
| 243 | + TransportVersion serializedAtVersion, |
| 244 | + @Nullable NamedWriteableRegistry registry |
| 245 | + ) { |
| 246 | + StreamInput out = registry == null |
| 247 | + ? new DeduplicateStreamInput(in, new DeduplicatorCache()) |
| 248 | + : new DeduplicateNamedWriteableAwareStreamInput(in, registry, new DeduplicatorCache()); |
| 249 | + out.setTransportVersion(serializedAtVersion); |
| 250 | + return out; |
| 251 | + } |
| 252 | + |
244 | 253 | /** An object implementing this interface can deduplicate instance of the provided objects.*/
|
245 | 254 | public interface Deduplicator {
|
246 | 255 | <T> T deduplicate(T object);
|
|
0 commit comments