Here you can find the source of lengthNeeded(byte[] b)
public static int lengthNeeded(byte[] b)
//package com.java2s; //License from project: Open Source License public class Main { public static int lengthNeeded(byte[] b) { if (b[0] != 0) { return 8; }/*from ww w .j a v a 2s .c o m*/ if (b[1] != 0) { return 7; } if (b[2] != 0) { return 6; } if (b[3] != 0) { return 5; } if (b[4] != 0) { return 4; } if (b[5] != 0) { return 3; } if (b[6] != 0) { return 2; } if (b[7] != 0) { return 1; } return 0; } }