/** * Update the central directory signature of a .jar. * * @param file the file to process * @param searchPattern the search patter to use * @param badSkipBytes the bad bytes skip table * @param newSig the new signature * @param endSig the expected signature * @throws IOException */ private static void updateJar( final File file, final byte[] searchPattern, final int[] badSkipBytes, final int newSig, final int endSig) throws IOException { final RandomAccessFile raf = new RandomAccessFile(file, "rw"); try { final FileChannel channel = raf.getChannel(); try { long pos = channel.size() - ENDLEN; if (!validateEndRecord(file, channel, pos, endSig)) { pos = scanForEndSig(file, channel, searchPattern, badSkipBytes, endSig); } if (pos == -1) { // Don't fail patching if we cannot validate a valid zip PatchLogger.ROOT_LOGGER.cannotInvalidateZip(file.getAbsolutePath()); return; } // Update the central directory record channel.position(pos); final ByteBuffer buffer = ByteBuffer.allocate(4); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(newSig); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } } finally { safeClose(channel); } } finally { safeClose(raf); } }