public static void injectIcon(InputStream stream, DirectoryEntry root, int iconId) throws IOException {
    IconFile iconFile = new IconFile();
    iconFile.read(new OffsetTrackingInputStream(new DataInputStream(stream)));

    long languageId = getLanguage(root);

    DirectoryEntry iconsDir = root.findSubDir(DirectoryEntry.RT_ICON);
    Bin.ArrayOfBins<IconDirectory> sourceIcons = iconFile.getIcons();
    if (sourceIcons.size() < iconsDir.getSubDirs().size()) {
      throw new IOException(
        String.format("Number of icons in template file '%d' is larger than in provided icon file '%d'",
                      iconsDir.getSubDirs().size(), sourceIcons.size()));
    }

    updateGroupIcon(root, iconId, iconFile);

    for (int i = 0; i < sourceIcons.size(); i++) {
      IconDirectory iconDirectory = sourceIcons.get(i);
      DirectoryEntry subDirIcon = iconsDir.findSubDir(i + 1);
      if (subDirIcon == null) {
        subDirIcon = insertIcon(iconsDir, i+1, languageId);
      }
      subDirIcon.getRawResource().setBytes(iconDirectory.getBytes().getBytes());
    }
  }
public static void injectIcon(InputStream stream, DirectoryEntry root, int iconId)