}
// convert the string into a byte array
byte[] bytes = value.getBytes(charsetName);
// is this string longer than the fixed length?
if (bytes.length > fixedLength) {
throw new TlvConvertException("String", "length exceeds fixed length ["+fixedLength+"]");
}
// do we need to pad the string?
if (bytes.length < fixedLength) {
// create a new byte array with a null byte
byte[] bytes0 = new byte[fixedLength];
System.arraycopy(bytes, 0, bytes0, 0, bytes.length);
bytes = bytes0; // use the new array
}
return new Tlv(tag, bytes);
} catch (UnsupportedEncodingException e) {
throw new TlvConvertException("String", "unsupported charset " + e.getMessage());
}
}