Skip null terminated sub strings from an array of bytes. - Android File Input Output

Android examples for File Input Output:Byte Array

Description

Skip null terminated sub strings from an array of bytes.

Demo Code

/**//from   ww  w  .  j  a v  a 2  s .  com
 *******************************************************************************
 * Copyright (C) 1996-2004, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */
//package com.java2s;

public class Main {
    /**
     * Skip null terminated substrings from an array of bytes.
     * Substring is a set of non-zero bytes starting from argument start to the 
     * next zero byte. If the first byte is a zero, the next byte will be taken as
     * the first byte.
     * @param array byte array
     * @param index to start substrings in byte count
     * @param skipcount number of null terminated substrings to skip
     * @return the end position of the substrings within the character array
     */
    static int skipNullTermByteSubString(byte[] array, int index,
            int skipcount) {
        byte b;
        for (int i = 0; i < skipcount; i++) {
            b = 1;
            while (b != 0) {
                b = array[index];
                index++;
            }
        }
        return index;
    }
}

Related Tutorials