code: 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;
                  final ScanContext context;
                  if (newSig == CRIPPLED_ENDSIG) {
                      context = new ScanContext(GOOD_ENDSIG_PATTERN, CRIPPLED_ENDSIG_PATTERN);
                  } else if (newSig == GOOD_ENDSIG) {
                      context = new ScanContext(CRIPPLED_ENDSIG_PATTERN, GOOD_ENDSIG_PATTERN);
                  } else {
                      context = null;
                  }
  
                  if (!validateEndRecord(file, channel, pos, endSig)) {
                      pos = scanForEndSig(file, channel, context);
                  }
                  if (pos == -1) {
                      if (context.state == State.NOT_FOUND) {
                          // 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);
          }
      }
docs: 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