Source:
<code>private InputStream createZip(SourceResponse sourceResponse, String transformerId) <START> throws CatalogTransformerException { <END> ServiceReference<MetacardTransformer> serviceRef = getTransformerServiceReference(transformerId); MetacardTransformer transformer = bundleContext.getService(serviceRef); String extension = getFileExtensionFromService(serviceRef); if (StringUtils.isNotBlank(extension)) { extension = "." + extension; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ZipOutputStream zipOutputStream = new ZipOutputStream(baos)) { for (Result result : sourceResponse.getResults()) { Metacard metacard = result.getMetacard(); BinaryContent binaryContent = transformer.transform(metacard, Collections.emptyMap()); ZipEntry entry = new ZipEntry(METACARD_PATH + metacard.getId() + extension); zipOutputStream.putNextEntry(entry); zipOutputStream.write(binaryContent.getByteArray()); zipOutputStream.closeEntry(); } return new ByteArrayInputStream(baos.toByteArray()); } catch (IOException e) { throw new CatalogTransformerException( "An error occurred while initializing or closing output stream", e); } }</code><technical_language>note .toByteArray() private InputStream createZip(SourceResponse sourceResponse, String transformerId) throws CatalogTransformerException { ServiceReference<MetacardTransformer> serviceRef = getTransformerServiceReference(transformerId); MetacardTransformer transformer = bundleContext.getService(serviceRef); String extension = getFileExtensionFromService(serviceRef); if (StringUtils.isNotBlank(extension)) { extension = "." + extension; } try (FileBackedOutputStream fileBackedOutputStream = new FileBackedOutputStream(THREASHOLD); ZipOutputStream zipOutputStream = new ZipOutputStream(fileBackedOutputStream)) { for (Result result : sourceResponse.getResults()) { Metacard metacard = result.getMetacard(); BinaryContent binaryContent = transformer.transform(metacard, Collections.emptyMap()); ZipEntry entry = new ZipEntry(METACARD_PATH + metacard.getId() + extension); zipOutputStream.putNextEntry(entry); zipOutputStream.write(binaryContent.getByteArray()); zipOutputStream.closeEntry(); } return fileBackedOutputStream.asByteSource().openStream(); } catch (IOException e) { throw new CatalogTransformerException( "An error occurred while initializing closing output stream", e); } }</technical_language>

Target:
private InputStream createZip(SourceResponse sourceResponse, String transformerId) throws CatalogTransformerException { ServiceReference<MetacardTransformer> serviceRef = getTransformerServiceReference(transformerId); MetacardTransformer transformer = bundleContext.getService(serviceRef); String extension = getFileExtensionFromService(serviceRef); if (StringUtils.isNotBlank(extension)) { extension = "." + extension; } try (FileBackedOutputStream fileBackedOutputStream = new FileBackedOutputStream(BUFFER_SIZE); ZipOutputStream zipOutputStream = new ZipOutputStream(fileBackedOutputStream)) { for (Result result : sourceResponse.getResults()) { Metacard metacard = result.getMetacard(); BinaryContent binaryContent = getTransformedMetacard(metacard, Collections.emptyMap(), transformer); if (binaryContent != null) { ZipEntry entry = new ZipEntry(METACARD_PATH + metacard.getId() + extension); zipOutputStream.putNextEntry(entry); zipOutputStream.write(binaryContent.getByteArray()); zipOutputStream.closeEntry(); } else { LOGGER.debug("Metacard with id was not added to zip file", metacard.getId()); } } return fileBackedOutputStream.asByteSource().openStream(); } catch (IOException e) { throw new CatalogTransformerException( "An error occurred while initializing or closing output stream", e); } }