blob: 70078100b41b3728696b1c1c860cf3b82530e348 (
plain)
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
|
package org.msgpack;
import java.nio.charset.Charset;
public class GenericRawRef extends GenericRaw {
int offset;
int length;
public GenericRawRef(byte[] bytes, int offset, int length)
{
this.bytes = bytes;
this.offset = offset;
this.length = length;
this.string = null;
}
public GenericRawRef(String string)
{
this.bytes = null;
this.string = string;
}
public synchronized void setString(String string)
{
this.string = string;
this.bytes = null;
}
public synchronized void setBytes(byte[] bytes)
{
this.bytes = bytes;
this.string = null;
}
private static Charset UTF8_CHARSET = Charset.forName("UTF-8");
@Override
public synchronized String asString()
{
if(string == null) {
return string = new String(bytes, UTF8_CHARSET);
}
return string;
}
@Override
public synchronized byte[] asBytes()
{
if(bytes == null) {
return bytes = string.getBytes(UTF8_CHARSET);
}
return bytes;
}
}
|