}
private void setAttributeValue(String value) {
- addTriplet(new AttributeValueTriplet(value));
+ if (state.encoding != -1) {
+ addTriplet(new AttributeValueTriplet(value, state.encoding));
+ } else {
+ addTriplet(new AttributeValueTriplet(value));
+ }
}
private void setEncoding(int encoding) {
public class AttributeValueTriplet extends AbstractTriplet {
private String attVal;
+ private int userEncoding = -1; //no encoding by default
+
/**
* Main constructor
*
this.attVal = truncate(attVal, MAX_LENGTH - 4);
}
+ public AttributeValueTriplet(String attVal, int userEncoding) {
+ this(attVal);
+ this.userEncoding = userEncoding;
+ }
+
/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = super.getData();
// convert name and value to ebcdic
byte[] tleByteValue = null;
try {
- tleByteValue = attVal.getBytes(AFPConstants.EBCIDIC_ENCODING);
+ if (this.userEncoding != -1) {
+ tleByteValue = attVal.getBytes("Cp" + userEncoding);
+ } else {
+ tleByteValue = attVal.getBytes(AFPConstants.EBCIDIC_ENCODING);
+ }
} catch (UnsupportedEncodingException usee) {
throw new IllegalArgumentException(attVal + " encoding failed");
}