Skip to content

It is expected to support InputStream #466

@linwaiwai

Description

@linwaiwai

Since we need to handle real-time image streams, converting the stream to a file for processing with exiftool and then converting it back to a stream introduces significant IO overhead, which is inefficient and wasteful.

   	String tempFileNamePrefix = "exiftool-input-" + UUID.randomUUID().toString();
   	File tempInputFile = File.createTempFile(tempFileNamePrefix,  extension);

   	try {
   	 
   		try (FileOutputStream tempInputFileStream = new FileOutputStream(tempInputFile)) {
   			byte[] buffer = new byte[1024];
   			int bytesRead;
   			while ((bytesRead = inputStream.read(buffer)) != -1) {
   				tempInputFileStream.write(buffer, 0, bytesRead);
   			}
   		}
   		exifTool.setImageMeta(tempInputFile, metadata);   
   		try (FileInputStream tempInputFileStream = new FileInputStream(tempInputFile)) {
   			byte[] buffer = new byte[1024];
   			int bytesRead;
   			while ((bytesRead = tempInputFileStream.read(buffer)) != -1) {
   				outputStream.write(buffer, 0, bytesRead);
   			}
   		}
   	} finally { 
   		tempInputFile.delete();
   	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions