blob: 6aa95310b8659e41a09b83ad4f63c723a332aae4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.slime;
/**
* A value type encapsulating a String in its UTF-8 representation.
* Useful for lazy decoding; if the data is just passed through in
* UTF-8 it will never be converted at all.
**/
final class Utf8Value extends Value {
private final byte[] value;
private String string;
public Utf8Value(byte[] value) { this.value = value; }
public final Type type() { return Type.STRING; }
public final String asString() {
if (string == null) {
string = Utf8Codec.decode(value, 0, value.length);
}
return string;
}
public final byte[] asUtf8() { return value; }
public final void accept(Visitor v) { v.visitString(value); }
}
|