Source:
public static List<OvfEntityData> getOvfEntities(byte[] tar, Guid storageDomainId) { List<OvfEntityData> ovfEntityDataFromTar = new ArrayList<>(); InputStream is = new ByteArrayInputStream(tar); log.infoFormat("Start fetching OVF files from tar file"); Map<String, ByteBuffer> filesFromTar; try (TarInMemoryExport memoryTar = new TarInMemoryExport(is)) { filesFromTar = memoryTar.unTar(); } catch (IOException e) { throw new RuntimeException(String.format("Exception while getting OVFs files from tar file for domain %s", storageDomainId), e); } for (Entry<String, ByteBuffer> fileEntry : filesFromTar.entrySet()) { if (fileEntry.getKey().endsWith(OVF_FILE_EXT)) { String ovfData = new String(fileEntry.getValue().array()); VmEntityType vmType = getVmEntityType(ovfData); ArchitectureType archType = null; try { XmlDocument xmlDocument = new XmlDocument(ovfData); archType = getOsSection(xmlDocument); } catch (Exception e) { log.errorFormat("Could not parse architecture type for VM. Exception : {0}", e); continue; } OvfEntityData ovfEntityData = createOvfEntityData(storageDomainId, ovfData, vmType, getEntityName(ovfData), archType, getEntityId(fileEntry.getKey())); log.infoFormat("Retrieve OVF Entity from storage domain id {0} for entity ID {1}, entity name {2} and vmType of {3}", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name()); ovfEntityDataFromTar.add(ovfEntityData); } else { log.infoFormat("File {0} is not an OVF file, will be ignored.", fileEntry.getKey()); } } log.infoFormat("Finish to fetch OVF files from tar file. The number of OVF entities are {0}", ovfEntityDataFromTar.size()); return ovfEntityDataFromTar; }

Target:
public static List<OvfEntityData> getOvfEntities(byte[] tar, Guid storageDomainId) { List<OvfEntityData> ovfEntityDataFromTar = new ArrayList<>(); InputStream is = new ByteArrayInputStream(tar); log.infoFormat("Start fetching OVF files from tar file"); Map<String, ByteBuffer> filesFromTar; try (TarInMemoryExport memoryTar = new TarInMemoryExport(is)) { filesFromTar = memoryTar.unTar(); } catch (IOException e) { throw new RuntimeException(String.format("Exception while getting OVFs files from tar file for domain %s", storageDomainId), e); } for (Entry<String, ByteBuffer> fileEntry : filesFromTar.entrySet()) { if (fileEntry.getKey().endsWith(OVF_FILE_EXT)) { String ovfData = new String(fileEntry.getValue().array()); VmEntityType vmType = getVmEntityType(ovfData); ArchitectureType archType = null; try { XmlDocument xmlDocument = new XmlDocument(ovfData); archType = getOsSection(xmlDocument); } catch (Exception e) { log.errorFormat("Could not parse architecture type for VM. Exception : {0}", e); continue; } OvfEntityData ovfEntityData = createOvfEntityData(storageDomainId, ovfData, vmType, getEntityName(ovfData), archType, getEntityId(fileEntry.getKey())); log.infoFormat("Retrieve OVF Entity from storage domain ID {0} for entity ID {1}, entity name {2} and VM Type of {3}", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name()); ovfEntityDataFromTar.add(ovfEntityData); } else { log.infoFormat("File {0} is not an OVF file, will be ignored.", fileEntry.getKey()); } } log.infoFormat("Finish to fetch OVF files from tar file. The number of OVF entities are {0}", ovfEntityDataFromTar.size()); return ovfEntityDataFromTar; }