code: @Override
    public int write(AudioInputStream stream, Type fileType, File out) throws IOException {
  
      // Check, if writing is supported
      if (!flacTypes[0].equals(fileType)) {
        throw new IllegalArgumentException("File type " + fileType + " not supported.");
      }
      else if(AudioStreamEncoder.getDataFormatSupport(stream.getFormat()) != AudioStreamEncoder.SUPPORTED  ) {
         throw new IllegalArgumentException("Data Format not supported");
      }
      
      FLACFileOutputStream flacFileOutputStream = null;
      int bytesWritten = 0;
      try {
        flacFileOutputStream = new FLACFileOutputStream(out);
        AudioFormat format = stream.getFormat();
  
        // Sanitize and optimize configurations
        StreamConfiguration streamConfiguration = adjustConfigurations(format);
        EncodingConfiguration encodingConfiguration = new EncodingConfiguration();
        FLACEncoder flac = new FLACEncoder();
        if (!flac.setStreamConfiguration(streamConfiguration) ||
                !flac.setEncodingConfiguration(encodingConfiguration)) {
          throw new IOException("FLAC encoder initialization failed.");
        }
  
        flac.setOutputStream(flacFileOutputStream);
        flac.openFLACStream();
  
        AudioStreamEncoder.encodeAudioInputStream(stream, MAX_READ, flac, false);
        
      } finally {
        if (flacFileOutputStream != null) {
          bytesWritten = Long.valueOf(flacFileOutputStream.size()).intValue();
          flacFileOutputStream.close();
        }
      }
  
      return bytesWritten;
    }
docs: /*
  (non-Javadoc)
  
  @see javax.sound.sampled.spi.AudioFileWriter#write(javax.sound.sampled.AudioInputStream,
  javax.sound.sampled.AudioFileFormat.Type, java.io.File)