| | |
| | | |
| | | |
| | | public class ByteUtil { |
| | | |
| | | |
| | | /** |
| | | * 将字节数组分割 |
| | | * @param bytes 被分割数组 |
| | | * @param fromIndex 分割起始位置 |
| | | * @param len 分割长度 |
| | | * @return 返回 分割出来的数组 |
| | | */ |
| | | public static byte[] bytesSplit(byte[] bytes, int fromIndex, int len){ |
| | | if(bytes == null){ |
| | | return null ; |
| | | }else{ |
| | | byte[] bs = new byte[len] ; |
| | | if(fromIndex + len > bytes.length){ |
| | | System.arraycopy(bytes, fromIndex, bs, 0, bytes.length - fromIndex) ; |
| | | }else{ |
| | | System.arraycopy(bytes, fromIndex, bs, 0, len) ; |
| | | } |
| | | return bs ; |
| | | } |
| | | } |
| | | /** |
| | | * 将字节数组分割 |
| | | * @param bytes 被分割数组 |
| | | * @param fromIndex 分割起始位置 |
| | | * @param len 分割长度 |
| | | * @return 返回 分割出来的数组 |
| | | */ |
| | | public static Object[] bytesSplit_(byte[] bytes, int fromIndex, int len){ |
| | | if(bytes == null){ |
| | | return null ; |
| | | }else{ |
| | | int realLen = len ; |
| | | byte[] bs = new byte[len] ; |
| | | if(fromIndex + len > bytes.length){ |
| | | System.arraycopy(bytes, fromIndex, bs, 0, bytes.length - fromIndex) ; |
| | | realLen = bytes.length - fromIndex ; |
| | | }else{ |
| | | System.arraycopy(bytes, fromIndex, bs, 0, len) ; |
| | | } |
| | | return new Object[]{bs, realLen} ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将字节数组合并到字节数组上 |
| | | * @param bGroup1 被合并数组 |