去除无效数据
(byte[] extra)
| 69 | * 去除无效数据 |
| 70 | */ |
| 71 | public static byte[] trim(byte[] extra) throws IOException { |
| 72 | int offset = 0; |
| 73 | while (extra.length - offset >= 4) { |
| 74 | int header = ZipUtil.readUShort(extra, offset); |
| 75 | int size = ZipUtil.readUShort(extra, offset + 2); |
| 76 | if (!KNOWN_HEADER.contains(header) || offset + 4 + size > extra.length) { |
| 77 | break; |
| 78 | } |
| 79 | offset += 4 + size; |
| 80 | } |
| 81 | return Arrays.copyOf(extra, offset); |
| 82 | } |
| 83 | |
| 84 | public static byte[] set(byte[] extra, int header, byte[] data) throws IOException { |
| 85 | extra = remove(extra, header); |