diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java |
Publish
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java b/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java new file mode 100644 index 00000000000..6aa95310b86 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java @@ -0,0 +1,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); } +} |