aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/hitfield/RawBase64.java
blob: 6660f1bf7125572f8bdd5fceb6c7c4822d234924 (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
// 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;
import java.util.Objects;

/**
 * Wraps a byte [] and renders it as base64 encoded string
 * @author baldersheim
 */
public class RawBase64 implements Comparable<RawBase64> {
    private final static Base64.Encoder encoder = Base64.getEncoder();
    private final byte[] content;
    public RawBase64(byte[] content) {
        Objects.requireNonNull(content);
        this.content = content;
    }

    public byte [] value() { return content; }

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

    @Override
    public String toString() {
        return encoder.encodeToString(content);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RawBase64 rawBase64 = (RawBase64) o;
        return Arrays.equals(content, rawBase64.content);
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(content);
    }
}