/** * Get the text encoding being used. * * The text encoding is defined by the frame body that the text field belongs to. * * @return the text encoding charset */ protected Charset getTextEncodingCharSet() { final byte textEncoding = this.getBody().getTextEncoding(); final Charset charSetName = TextEncoding.getInstanceOf().getCharsetForId(textEncoding); logger.finest("text encoding:" + textEncoding + " charset:" + charSetName.name()); return charSetName; } }
/** * Check the value can be encoded with the specified encoding * * @return */ public boolean canBeEncoded() { //Try and write to buffer using the CharSet defined by the textEncoding field (note if using UTF16 we dont //need to worry about LE,BE at this point it makes no difference) byte textEncoding = this.getBody().getTextEncoding(); String charSetName = TextEncoding.getInstanceOf().getValueForId(textEncoding); CharsetEncoder encoder = Charset.forName(charSetName).newEncoder(); if (encoder.canEncode((String) value)) { return true; } else { // logger.finest("Failed Trying to decode" + value + "with" + encoder.toString()); return false; } } }
/** * Check the value can be encoded with the specified encoding * @return */ public boolean canBeEncoded() { //Try and write to buffer using the CharSet defined by the textEncoding field (note if using UTF16 we dont //need to worry about LE,BE at this point it makes no difference) byte textEncoding = this.getBody().getTextEncoding(); String charSetName = TextEncoding.getInstanceOf().getValueForId(textEncoding); CharsetEncoder encoder = Charset.forName(charSetName).newEncoder(); if (encoder.canEncode((String) value)) { return true; } else { logger.finest("Failed Trying to decode" + value + "with" + encoder.toString()); return false; } } }
/** * Check the value can be encoded with the specified encoding * @return */ public boolean canBeEncoded() { //Try and write to buffer using the CharSet defined by the textEncoding field (note if using UTF16 we dont //need to worry about LE,BE at this point it makes no difference) final byte textEncoding = this.getBody().getTextEncoding(); final TextEncoding encoding = TextEncoding.getInstanceOf(); final Charset charset = encoding.getCharsetForId(textEncoding); CharsetEncoder encoder = charset.newEncoder(); if (encoder.canEncode((String) value)) { return true; } else { logger.finest("Failed Trying to decode" + value + "with" + encoder.toString()); return false; } }