blob: 6f3caf244714a4ec93428e685d3bc2da5c223461 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.storage.searcher;
import com.yahoo.documentapi.ProgressToken;
import com.yahoo.search.result.Hit;
import java.io.IOException;
import java.util.Base64;
public class ContinuationHit extends Hit {
private final String value;
public ContinuationHit(ProgressToken token) {
super("continuation");
final byte[] serialized = token.serialize();
value = Base64.getUrlEncoder().encodeToString(serialized);
}
public static ProgressToken getToken(String continuation) throws IOException {
byte[] serialized;
try {
serialized = Base64.getUrlDecoder().decode(continuation);
} catch (IllegalArgumentException e) {
// Legacy visitor tokens were encoded with MIME Base64 which may fail decoding as URL-safe.
// Try again with MIME decoder to avoid breaking upgrade scenarios.
// TODO(vekterli): remove once this is no longer a risk.
serialized = Base64.getMimeDecoder().decode(continuation);
}
return new ProgressToken(serialized);
}
public String getValue() {
return value;
}
}
|