Android Open Source - FlashTransmitter A S C I I Scheme






From Project

Back to project page FlashTransmitter.

License

The source code is released under:

GNU General Public License

If you think the Android project FlashTransmitter 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.catinthedark.flash_transmitter.lib.algorithm;
// w  ww  . j  ava2s  .  c om

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by Ilya on 15.04.2014.
 */
public class ASCIIScheme implements EncodingScheme {
    public final int BLOCK_SIZE = 8;

    @Override
    public Byte[] getCodes(String str) {
        byte[] codes = str.getBytes();
        Byte[] wrapped_codes = new Byte[codes.length];
        int i = 0;
        for (byte b: codes) {
            wrapped_codes[i++] = b;
        }

        return wrapped_codes;
    }

    @Override
    public String getSymbols(Byte[] codesObjects) {
        byte[] codes = new byte[codesObjects.length];
        int i = 0;
        for (Byte b: codesObjects) {
            codes[i++] = b;
        }

        return new String(codes);
    }

    @Override
    public Byte[] getBitCodes(String str) {
        Byte[] codes = getCodes(str);
        ArrayList<Byte> bitCodes = new ArrayList<Byte>(codes.length * BLOCK_SIZE);
        for (Byte code: codes) {
            bitCodes.addAll(Arrays.asList(codeToBits(code)));
        }

        return bitCodes.toArray(new Byte[bitCodes.size()]);
    }

    private Byte[] codeToBits(Byte code) {
        Byte[] bits = new Byte[BLOCK_SIZE];

        for (byte i = 0; i < BLOCK_SIZE; i++) {
            bits[i] = (byte)((code >> i) & 1);
        }

        return bits;
    }

    @Override
    public String getSymbolsByBits(Byte[] bitCodes) {
        Byte[] codes = new Byte[bitCodes.length / BLOCK_SIZE]; // but we need bitCodes.length / BLOCK_SIZE memory. LOL

        for (byte i = 0; i < bitCodes.length / BLOCK_SIZE; ++i) {
            codes[i] = 0;
        }

        byte aByte = 0;
        for (byte i = 0; i < bitCodes.length; i++) {
            aByte += (byte)(bitCodes[i] << (i % BLOCK_SIZE));
            if (i % BLOCK_SIZE == BLOCK_SIZE - 1) {
                codes[i / BLOCK_SIZE] = aByte;
                aByte = 0;
            }
        }

        return getSymbols(codes);
    }
}




Java Source Code List

com.catinthedark.activity.ReceiveActivity.java
com.catinthedark.activity.StartActivity.java
com.catinthedark.activity.TransmitActivity.java
com.catinthedark.flash_transmitter.lib.algorithm.ASCIIScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.CompressedScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.Converter.java
com.catinthedark.flash_transmitter.lib.algorithm.EmptyErrorCorrectionLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.EmptyLogicalCodeLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.EncodingScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.ErrorCorrectionLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.Filter.java
com.catinthedark.flash_transmitter.lib.algorithm.LineCoder.java
com.catinthedark.flash_transmitter.lib.algorithm.LogicalCodeLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.ManchesterLineCoder.java
com.catinthedark.flash_transmitter.lib.algorithm.ManchesterSynchronizer.java
com.catinthedark.flash_transmitter.lib.algorithm.RawDataTranslator.java
com.catinthedark.flash_transmitter.lib.algorithm.Synchronizer.java
com.catinthedark.flash_transmitter.lib.factories.EncodingSchemeFactory.java
com.catinthedark.flash_transmitter.lib.factories.ErrorCorrectionFactory.java
com.catinthedark.flash_transmitter.lib.factories.LineCoderFactory.java
com.catinthedark.flash_transmitter.lib.factories.LogicalCodeFactory.java
com.catinthedark.task.SubmitDataTask.java