Java String Split split(byte[] input)

Here you can find the source of split(byte[] input)

Description

split

License

Open Source License

Declaration

public static byte[][] split(byte[] input) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    public static byte[][] split(byte[] input) {
        ArrayList<byte[]> bytes = new ArrayList<byte[]>();
        int index_cache = 0;

        for (int i = 0; i < input.length; i++) {
            if (input[i] == 0x00) {
                byte[] b = subarray(input, index_cache, i - 1);
                bytes.add(b);//from  w w w  . ja v a 2s.c  om
                index_cache = i + 1;
            }
        }
        if (index_cache != 0) {
            byte[] b = subarray(input, index_cache, input.length - 1);
            bytes.add(b);
        }

        byte[][] output = new byte[bytes.size()][input.length];
        for (int i = 0; i < bytes.size(); i++) {
            output[i] = bytes.get(i);
        }

        return output;
    }

    public static byte[] subarray(byte[] in, int arg1, int arg2) {
        byte[] out = new byte[(arg2 - arg1) + 1];

        if (arg2 - arg1 > in.length) {
            return in;
        }
        for (int i = arg1; i <= arg2; i++) {
            out[i - arg1] = in[i];
        }

        return out;
    }
}

Related

  1. recursiveSplit(String str, String splitor)
  2. safeSplitParameters(String parameters)
  3. split(byte[] bytes, byte[] p)
  4. split(byte[] data)
  5. split(byte[] input)
  6. split(final byte[] array, final int chunkSize)
  7. split(final int limit, String text)
  8. split(final String s)
  9. split(final String s)