public String getCharacterSet() { return characterSetForTextEncoding(textEncoding); }
public void setTextEncoding(byte textEncoding, boolean transcode) throws CharacterCodingException { if (this.textEncoding != textEncoding) { CharBuffer charBuffer = bytesToCharBuffer(this.value, characterSetForTextEncoding(this.textEncoding)); byte[] transcodedBytes = charBufferToBytes(charBuffer, characterSetForTextEncoding(textEncoding)); this.textEncoding = textEncoding; this.value = transcodedBytes; } }
@Override public String toString() { try { return bytesToString(value, characterSetForTextEncoding(textEncoding)); } catch (CharacterCodingException e) { return null; } }
public EncodedText(byte textEncoding, String string) { this.textEncoding = textEncoding; value = stringToBytes(string, characterSetForTextEncoding(textEncoding)); this.stripBomAndTerminator(); }
public EncodedText(String string) throws IllegalArgumentException { for (byte textEncoding : textEncodingFallback) { this.textEncoding = textEncoding; value = stringToBytes(string, characterSetForTextEncoding(textEncoding)); if (value != null && this.toString() != null) { this.stripBomAndTerminator(); return; } } throw new IllegalArgumentException("Invalid string, could not find appropriate encoding"); }
public byte[] toBytes(boolean includeBom, boolean includeTerminator) { characterSetForTextEncoding(textEncoding); // ensured textEncoding is valid int newLength = value.length + (includeBom ? boms[textEncoding].length : 0) + (includeTerminator ? getTerminator().length : 0); if (newLength == value.length) { return value; } else { byte bytes[] = new byte[newLength]; int i = 0; if (includeBom) { byte[] bom = boms[textEncoding]; if (bom.length > 0) { System.arraycopy(boms[textEncoding], 0, bytes, i, boms[textEncoding].length); i += boms[textEncoding].length; } } if (value.length > 0) { System.arraycopy(value, 0, bytes, i, value.length); i += value.length; } if (includeTerminator) { byte[] terminator = getTerminator(); if (terminator.length > 0) { System.arraycopy(terminator, 0, bytes, i, terminator.length); } } return bytes; } }
public String getCharacterSet() { return characterSetForTextEncoding(textEncoding); }
public void setTextEncoding(byte textEncoding, boolean transcode) throws CharacterCodingException { if (this.textEncoding != textEncoding) { CharBuffer charBuffer = bytesToCharBuffer(this.value, characterSetForTextEncoding(this.textEncoding)); byte[] transcodedBytes = charBufferToBytes(charBuffer, characterSetForTextEncoding(textEncoding)); this.textEncoding = textEncoding; this.value = transcodedBytes; } }
@Override public String toString() { try { return bytesToString(value, characterSetForTextEncoding(textEncoding)); } catch (CharacterCodingException e) { return null; } }
public EncodedText(byte textEncoding, String string) { this.textEncoding = textEncoding; value = stringToBytes(string, characterSetForTextEncoding(textEncoding)); this.stripBomAndTerminator(); }
public byte[] toBytes(boolean includeBom, boolean includeTerminator) { characterSetForTextEncoding(textEncoding); // ensured textEncoding is valid int newLength = value.length + (includeBom ? boms[textEncoding].length : 0) + (includeTerminator ? getTerminator().length : 0); if (newLength == value.length) { return value; } else { byte bytes[] = new byte[newLength]; int i = 0; if (includeBom) { byte[] bom = boms[textEncoding]; if (bom.length > 0) { System.arraycopy(boms[textEncoding], 0, bytes, i, boms[textEncoding].length); i += boms[textEncoding].length; } } if (value.length > 0) { System.arraycopy(value, 0, bytes, i, value.length); i += value.length; } if (includeTerminator) { byte[] terminator = getTerminator(); if (terminator.length > 0) { System.arraycopy(terminator, 0, bytes, i, terminator.length); } } return bytes; } }
public EncodedText(String string) throws IllegalArgumentException { for (byte textEncoding : textEncodingFallback) { this.textEncoding = textEncoding; value = stringToBytes(string, characterSetForTextEncoding(textEncoding)); if (value != null && this.toString() != null) { this.stripBomAndTerminator(); return; } } throw new IllegalArgumentException("Invalid string, could not find appropriate encoding"); }