| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata; |
| 22 |
|
| 23 |
import com.drew.lang.annotations.NotNull; |
| 24 |
import com.drew.lang.annotations.Nullable; |
| 25 |
|
| 26 |
import java.io.UnsupportedEncodingException; |
| 27 |
import java.nio.charset.Charset; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public final class StringValue |
| 33 |
{ |
| 34 |
@NotNull |
| 35 |
private final byte[] _bytes; |
| 36 |
|
| 37 |
@Nullable |
| 38 |
private final Charset _charset; |
| 39 |
|
| 40 |
public StringValue(@NotNull byte[] bytes, @Nullable Charset charset) |
| 41 |
{ |
| 42 |
_bytes = bytes; |
| 43 |
_charset = charset; |
| 44 |
} |
| 45 |
|
| 46 |
@NotNull |
| 47 |
public byte[] getBytes() |
| 48 |
{ |
| 49 |
return _bytes; |
| 50 |
} |
| 51 |
|
| 52 |
@Nullable |
| 53 |
public Charset getCharset() |
| 54 |
{ |
| 55 |
return _charset; |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public String toString() |
| 60 |
{ |
| 61 |
return toString(_charset); |
| 62 |
} |
| 63 |
|
| 64 |
public String toString(@Nullable Charset charset) |
| 65 |
{ |
| 66 |
if (charset != null) { |
| 67 |
try { |
| 68 |
return new String(_bytes, charset.name()); |
| 69 |
} catch (UnsupportedEncodingException ex) { |
| 70 |
|
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
return new String(_bytes); |
| 75 |
} |
| 76 |
} |