public static AudioFormat getNativeAudioFormat(AudioFormat format, Mixer mixer) { Line.Info[] lineInfos;  if (mixer != null) { lineInfos = mixer.getTargetLineInfo (new Line.Info(TargetDataLine.class)); } else { lineInfos = AudioSystem.getTargetLineInfo (new Line.Info(TargetDataLine.class)); }  AudioFormat nativeFormat = null;   for (int i = 0; i < lineInfos.length; i++) {  AudioFormat[] formats = ((TargetDataLine.Info)lineInfos[i]).getFormats();  for (int j = 0; j < formats.length; j++) {     AudioFormat thisFormat = formats[j]; if (thisFormat.getEncoding() == format.getEncoding() && thisFormat.isBigEndian() == format.isBigEndian() && thisFormat.getSampleSizeInBits() == format.getSampleSizeInBits() && thisFormat.getSampleRate() >= format.getSampleRate()) { nativeFormat = thisFormat; break; } } if (nativeFormat != null) {  break; } } return nativeFormat;
public static AudioFormat getNativeAudioFormat(AudioFormat format) { return getNativeAudioFormat(format, null);
    public static AudioFormat getNativeAudioFormat(AudioFormat format,                                                   Mixer mixer) {        Line.Info[] lineInfos;                if (mixer != null) {            lineInfos = mixer.getTargetLineInfo                (new Line.Info(TargetDataLine.class));        } else {            lineInfos = AudioSystem.getTargetLineInfo                (new Line.Info(TargetDataLine.class));        }                AudioFormat nativeFormat = null;        // find a usable target line        for (int i = 0; i < lineInfos.length; i++) {                        AudioFormat[] formats =                 ((TargetDataLine.Info)lineInfos[i]).getFormats();                        for (int j = 0; j < formats.length; j++) {                                // for now, just accept downsampling, not checking frame                // size/rate (encoding assumed to be PCM)                                AudioFormat thisFormat = formats[j];                if (thisFormat.getEncoding() == format.getEncoding()                    && thisFormat.isBigEndian() == format.isBigEndian()                    && thisFormat.getSampleSizeInBits() ==                     format.getSampleSizeInBits()                    && thisFormat.getSampleRate() >= format.getSampleRate()) {                    nativeFormat = thisFormat;                    break;                }            }            if (nativeFormat != null) {                //no need to look through remaining lineinfos                break;            }        }        return nativeFormat;    }