java stereo to mono conversion unsupported conversion error

I am trying to convert a stereo wav file into mono here is my code:
AudioInputStream inputAIS = AudioSystem.getAudioInputStream(sourceFile);

if (inputAIS.getFormat().getChannels() == 2)
			inputAIS = convertChannels(1, inputAIS);
			if (DEBUG) out("stream: " + inputAIS);

 private static AudioInputStream convertChannels(
            int nChannels,
            AudioInputStream sourceStream) {
        AudioFormat sourceFormat = sourceStream.getFormat();
        AudioFormat targetFormat = new AudioFormat(
        return AudioSystem.getAudioInputStream(targetFormat, sourceStream);

 private static int calculateFrameSize(int nChannels, int nSampleSizeInBits)
		return ((nSampleSizeInBits + 7) / 8) * nChannels;

Open in new window

And I am getting an error:

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported conversion: PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian from PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
        at javax.sound.sampled.AudioSystem.getAudioInputStream(
        at sound.AudioDataBuffer.convertChannels(
        at sound.AudioDataBuffer.main(
Java Result: 1

Function convertChannels comes from here:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chudyksgAuthor Commented:
I solved it. It needs Tritonous pcm2pcm converter installed.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chudyksgAuthor Commented:
I found the solution on my own
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.