public void writeStoreFileChunkToDisk(String outputFilePath, StoreFileChunk storeFileChunk) throws IOException {
    // Verify service is running
    validateIfFileStoreIsRunning();

    // Validate input
    Objects.requireNonNull(storeFileChunk, "storeFileChunk must not be null");
    Objects.requireNonNull(storeFileChunk.getStream(), "dataInputStream in storeFileChunk must not be null");

    // Can add buffered streaming to avoid memory overusage if multiple threads calling FileStore.
    // Read the entire file content into memory
    int fileSize = storeFileChunk.getStream().available();
    byte[] content = Utils.readBytesFromStream(storeFileChunk.getStream(), fileSize);

    Path outputPath = Paths.get(outputFilePath);
    Path parentDir = outputPath.getParent();
    String targetPathString = "";
    try {
      synchronized (storeWriteLock) {
        String targetOutputString = updatePathWithResetCompactionIndex(outputFilePath);
        Path targetOutputPath = Paths.get(targetOutputString);
        // Validate if parent directory exists
        if (parentDir != null && !Files.exists(parentDir)) {
          // Throwing IOException if the parent directory does not exist
          throw new IOException("Parent directory does not exist: " + parentDir);
        }
        if(lastExecutedFuture != null){
          lastExecutedFuture.get();
        }

        // Write content to file with create and append options, which will create a new file if file doesn't exist
        // and append to the existing file if file exists
        Future<?> currentAsynWriteTaskFuture = executor.submit(() -> {
          try (FileOutputStream fos = new FileOutputStream(targetOutputPath.toFile(), true)) {
            fos.write(content);
            fos.flush();
          } catch (IOException e) {
            logger.error("Error while writing chunk to file: {}", outputFilePath, e);
          }
        });
        lastExecutedFuture = currentAsynWriteTaskFuture;
      }
    } catch (Exception e) {
      logger.error("Error while writing chunk to file: {}", targetPathString, e);
      throw new FileStoreException("Error while writing chunk to file: " + targetPathString,
          FileStoreWriteError);
    }
    logger.info("Write successful for chunk to file: {} with size: {}", targetPathString, content.length);
  }
Writes data from an input stream to a file.
@param outputFilePath  The path where the file should be written
@param storeFileChunk The StoreFileChunk object representing input stream containing the data to write
@throws IOException              if there are issues writing the file
@throws FileStoreException       if the service is not running
@throws IllegalArgumentException if fileInputStream is null
ambry-store/src/main/java/com/github/ambry/store/FileStore.java