Android Open Source - TextEncoder Ascii Message






From Project

Back to project page TextEncoder.

License

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.

Java Source Code

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());
    }
}




Java Source Code List

com.csab.TextEncoder.AsciiMessage.java
com.csab.TextEncoder.Base64Message.java
com.csab.TextEncoder.BinaryMessage.java
com.csab.TextEncoder.Converter.java
com.csab.TextEncoder.DecimalMessage.java
com.csab.TextEncoder.HexMessage.java
com.csab.TextEncoder.MainActivity.java
com.csab.TextEncoder.Message.java
com.csab.TextEncoder.OctalMessage.java