aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/hitfield/RawBase64.java
blob: ada0797ab027718167a0bc98c0936658033a8973 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.hitfield;

import java.util.Arrays;
import java.util.Base64;

/**
 * @author baldersheim
 */
public class RawBase64 implements Comparable<RawBase64> {
    private final byte[] content;
    private final boolean withoutPadding;
    public RawBase64(byte[] content) {
        this(content, false);
    }
    public RawBase64(byte[] content, boolean withoutPadding) {
        this.content = content;
        this.withoutPadding = withoutPadding;
    }

    @Override
    public int compareTo(RawBase64 rhs) {
        return Arrays.compareUnsigned(content, rhs.content);
    }

    @Override
    public String toString() {
        return withoutPadding
                ? Base64.getEncoder().withoutPadding().encodeToString(content)
                : Base64.getEncoder().encodeToString(content);
    }
}