Here you can find the source of readWavHeader(DataInputStream inStrm, FileChannel fc)
private static boolean readWavHeader(DataInputStream inStrm, FileChannel fc)
//package com.java2s; import java.io.DataInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; public class Main { public static int srcChannels, dstChannels, srcBPS; public static int srcSamplingRate, dstSamplingRate, dstBPS; public static long length = 0; private static boolean readWavHeader(DataInputStream inStrm, FileChannel fc) { byte[] buf = new byte[16]; int size; ByteBuffer bb = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN); bb.clear();/*w w w . j a v a 2s . co m*/ try { inStrm.readInt(); inStrm.readFully(buf, 0, 8); if (!"WAVEfmt ".equals(new String(buf, 0, 8))) return false; inStrm.readFully(buf, 0, 4); size = bb.getInt(); if (size > buf.length) { buf = new byte[size]; bb = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN); } inStrm.readFully(buf, 0, size); bb.clear(); if (bb.getShort() != 1) { System.err.println(String.format("Error: Only PCM is supported.")); return false; } srcChannels = bb.getShort(); srcSamplingRate = bb.getInt(); srcBPS = bb.getInt(); if ((int) srcBPS % srcSamplingRate * srcChannels != 0) return false; srcBPS /= srcSamplingRate * srcChannels; byte[] cbuf = new byte[4]; for (;;) { inStrm.readFully(cbuf, 0, 4); try { bb.clear(); inStrm.readFully(buf, 0, 4); length = (long) bb.getInt(); } catch (IOException ex) { break; } if ("data".equals(new String(cbuf, 0, 4))) break; fc.position(fc.position() + length); } if (fc.position() > fc.size()) { System.err.println(String.format("Couldn't find data chank")); return false; } if (srcBPS != 1 && srcBPS != 2 && srcBPS != 3 && srcBPS != 4) { System.err.println(String.format("Error : Only 8bit, 16bit, 24bit and 32bit PCM are supported.")); return false; } } catch (IOException e1) { System.err.println("Error reading file header"); return false; } return true; } }