blob: 5cdaf0ab5db1b6dc393f291f5893e2d1ecb2e66f (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;
import com.yahoo.document.DataType;
import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import java.util.Base64;
/**
* @author Simon Thoresen Hult
*/
public final class Base64EncodeExpression extends Expression {
public Base64EncodeExpression() {
super(DataType.LONG);
}
@Override
protected void doExecute(ExecutionContext context) {
long input = ((LongFieldValue) context.getValue()).getLong();
byte[] output = new byte[8];
for (int i = 0; i < output.length; ++i) {
output[i] = (byte)(input & 0xffL);
input >>>= 8;
}
String encoded = Base64.getEncoder().encodeToString(output);
context.setValue(new StringFieldValue(encoded));
}
@Override
protected void doVerify(VerificationContext context) {
context.setValueType(createdOutputType());
}
@Override
public DataType createdOutputType() {
return DataType.STRING;
}
@Override
public String toString() {
return "base64encode";
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Base64EncodeExpression)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return getClass().hashCode();
}
}
|