Android Byte Array Cut deleteSpace(byte[] b)

Here you can find the source of deleteSpace(byte[] b)

Description

delete Space

Declaration

public static void deleteSpace(byte[] b) 

Method Source Code

//package com.java2s;

public class Main {

    public static void deleteSpace(byte[] b) {
        int len = b.length;
        if ((len & 1) == 1) {
            b[len - 1] = '\0';
            len--;/*w w  w . j av  a 2  s. c  om*/
        }
        int count = 0;
        for (int i = 0; i < len; i += 2) {
            int high = b[i] & 0xff;
            int low = b[i + 1] & 0xff;
            if (high == '\0' || low == '\0') {
                count = count + len - i;
                break;
            } else if (high == 0x21 && low == 0x21) {
                count += 2;
            } else {
                b[i - count] = (byte) high;
                b[i - count + 1] = (byte) low;
            }
        }
        if (count > 0) {
            int size = b.length;
            for (int i = len - count; i < size; i++) {
                b[i] = '\0';
            }
        }
    }
}

Related

  1. cutBytes(byte[] bytes, int pos, int length)
  2. deleteMark(byte[] b)
  3. deleteSpaceLatin(byte[] b)
  4. remove(byte[] data, int place)