Here you can find the source of startsWith(byte[] p, byte id)
Parameter | Description |
---|---|
p | - array of bytes to check |
id | - expected value of the first non-zero byte |
public static boolean startsWith(byte[] p, byte id)
//package com.java2s; /*//from w w w. j av a 2 s .c o m Copyright 2012, Jernej Kovacic Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ public class Main { /** * A convenience function to determine whether the first non-zero byte is * equal to a specific value. Typically used to determine whether a blob * represents an EC point in compressed or uncompressed form. * * @param p - array of bytes to check * @param id - expected value of the first non-zero byte * * @return whether the first non-zero byte is equal to id */ public static boolean startsWith(byte[] p, byte id) { // sanity check if (null == p || 0 == p.length) { return false; } int start = 0; for (start = 0; start < p.length && 0x00 == p[start]; start++) ; if (p.length <= start) { return false; } return (id == p[start]); } }