Back to project page TextEncoder.
The source code is released under:
Apache License
If you think the Android project TextEncoder listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.csab.TextEncoder; //from w ww. ja v a 2s .c o m import java.util.Arrays; import android.content.Context; import org.apache.commons.codec.binary.StringUtils; public class AsciiMessage extends Message { public AsciiMessage(byte[] inputArray) { super(inputArray); } public AsciiMessage(String inputString, Context context) { setByteValuesArray(inputString.getBytes()); } public AsciiMessage(long[] inputArray) throws NumberFormatException { long[] sortedArray = Arrays.copyOf(inputArray, inputArray.length); Arrays.sort(sortedArray); if (sortedArray[sortedArray.length - 1] > Byte.MAX_VALUE) { // TODO: Get a context to access this message from strings.xml throw new NumberFormatException("Value outside ASCII code range (127)"); } else { byte[] byteArray = new byte[inputArray.length]; for (int i = 0; i < inputArray.length; i++) { byteArray[i] = (byte) inputArray[i]; } setByteValuesArray(byteArray); } } public <T> T convert(Class<T> clazz) throws Exception { return clazz.getConstructor(byte[].class).newInstance(getByteValuesArray()); } @Override public String toString() { return StringUtils.newStringUsAscii(getByteValuesArray()); } }