Android InputStream Split split(InputStream input)

Here you can find the source of split(InputStream input)

Description

split

License

Open Source License

Declaration

static public Collection<byte[]> split(InputStream input) 

Method Source Code

//License from project: Open Source License 

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class Main{
    static public Collection<byte[]> split(InputStream input) {
        Collection<byte[]> files = new ArrayList<byte[]>();

        try {/*from   www.  j av a2 s.  c  om*/
            byte[] data = new byte[input.available()];
            int pos = 0;
            byte fileHdrSize;
            int fileDataSize;
            int fileSize;

            input.read(data);

            while (pos < data.length) {
                fileHdrSize = data[pos];
                fileDataSize = data[pos + 4] & 0xFF;
                fileDataSize |= (int) (data[pos + 5] & 0xFF) << 8;
                fileDataSize |= (int) (data[pos + 6] & 0xFF) << 16;
                fileDataSize |= (int) (data[pos + 7] & 0xFF) << 24;

                if (data[pos + 8] != '.')
                    break;
                if (data[pos + 9] != 'F')
                    break;
                if (data[pos + 10] != 'I')
                    break;
                if (data[pos + 11] != 'T')
                    break;

                fileSize = fileHdrSize + fileDataSize + 2;

                if ((pos + fileSize) > data.length)
                    break;

                files.add(Arrays.copyOfRange(data, pos, pos + fileSize));
                pos += fileSize;
            }

            if (pos < data.length)
                files.add(Arrays.copyOfRange(data, pos, data.length));
        } catch (IOException e) {
        }

        return files;
    }
}