class PcmWavConverter {

    public static void convertPCMToWav(WaveHeader waveHeader,final String pcmFilePath, final String wavFilePath)throws IOException{
        if (waveHeader ==null){
            throw new IllegalArgumentException("waveHeader cannot be null");
        }

        if (pcmFilePath==null || pcmFilePath.trim().isEmpty()){
            throw new IllegalArgumentException("pcmFilePath cannot be null, empty, blank");
        }
        final File pcmFile=new File(pcmFilePath);

        if (wavFilePath==null || wavFilePath.trim().isEmpty()){
            throw new IllegalArgumentException("wavFilePath cannot be null, empty, blank");
        }
        final DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(wavFilePath)));
        final DataInputStream dataInputStream=new DataInputStream(new BufferedInputStream(new FileInputStream(pcmFile)));
        try {
            writeWavHeader(waveHeader,dataOutputStream,new File(pcmFilePath));
            writePCMData(dataOutputStream, dataInputStream);
        }
        finally {
            dataOutputStream.flush();
            dataOutputStream.close();
            dataInputStream.close();
        }
        final File partWavFile=new File(wavFilePath);
        if (!partWavFile.renameTo(new File(wavFilePath))){
            throw new IOException("Unable to rename file to:"+wavFilePath);
        }
    }

}