Source:
public Response downloadSegment( @ApiParam(value = "Name of the table with type REALTIME OR OFFLINE", required = true, example = "myTable_OFFLINE") @PathParam("tableNameWithType") String tableNameWithType, @ApiParam(value = "Name of the segment", required = true) @PathParam("segmentName") @Encoded String segmentName, @Context HttpHeaders httpHeaders) throws Exception { LOGGER.info("Received a request to download segment for table {}", segmentName, tableNameWithType); TableDataManager tableDataManager = checkGetTableDataManager(tableNameWithType); SegmentDataManager segmentDataManager = tableDataManager.acquireSegment(segmentName); if (segmentDataManager == null) { throw new WebApplicationException( String.format("Table %s segment %s does not exist", tableNameWithType, segmentName), Response.Status.NOT_FOUND); } try { String tableDir = tableDataManager.getTableDataDir(); String tarFilePath = TarGzCompressionUtils.createTarGzOfDirectory(tableDir + File.separator + segmentName); File tarFile = new File(tarFilePath); Response.ResponseBuilder builder = Response.ok(); builder.entity((StreamingOutput) output -> { try { Files.copy(tarFile.toPath(), output); } finally { FileUtils.deleteQuietly(tarFile); } }); builder.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + tarFile.getName()); builder.header(HttpHeaders.CONTENT_LENGTH, tarFile.length()); return builder.build(); } finally { tableDataManager.releaseSegment(segmentDataManager); } }

Target:
public Response downloadSegment( @ApiParam(value = "Name of the table with type REALTIME OR OFFLINE", required = true, example = "myTable_OFFLINE") @PathParam("tableNameWithType") String tableNameWithType, @ApiParam(value = "Name of the segment", required = true) @PathParam("segmentName") @Encoded String segmentName, @Context HttpHeaders httpHeaders) throws Exception { LOGGER.info("Received a request to download segment for table {}", segmentName, tableNameWithType); TableDataManager tableDataManager = checkGetTableDataManager(tableNameWithType); SegmentDataManager segmentDataManager = tableDataManager.acquireSegment(segmentName); if (segmentDataManager == null) { throw new WebApplicationException( String.format("Table %s segment %s does not exist", tableNameWithType, segmentName), Response.Status.NOT_FOUND); } try { File tmpSegmentTarDir = new File(serverInstance.getInstanceDataManager().getSegmentFileDirectory(), PEER_SEGMENT_DOWNLOAD_DIR); tmpSegmentTarDir.mkdir(); String tarFilePath = TarGzCompressionUtils .createTarGzOfDirectory(new File(tableDataManager.getTableDataDir(), segmentName).getAbsolutePath(), new File(tmpSegmentTarDir, tableNameWithType+ "_" + segmentName + "_" + UUID.randomUUID()).getAbsolutePath()); File tarFile = new File(tarFilePath); tarFile.deleteOnExit(); Response.ResponseBuilder builder = Response.ok(); builder.entity((StreamingOutput) output -> { try { Files.copy(tarFile.toPath(), output); } finally { FileUtils.deleteQuietly(tarFile); } }); builder.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + tarFile.getName()); builder.header(HttpHeaders.CONTENT_LENGTH, tarFile.length()); return builder.build(); } finally { tableDataManager.releaseSegment(segmentDataManager); } }