Copying data from the InputStream to the output DataLine.

Java to go!
Java Sound QuickStart

Tony Loton
Listing 5. Copying data from the InputStream to the output DataLine.


int frameSizeInBytes = format.getFrameSize();

int bufferLengthInFrames
 =line.getBufferSize() / 8;

int bufferLengthInBytes
 = bufferLengthInFrames * frameSizeInBytes;

byte[] data = new byte[bufferLengthInBytes];

int numBytesRead = 0;

if ((numBytesRead = stream.read(data)) != -1)
{
int numBytesRemaining = numBytesRead;
  line.write(data, 0, numBytesRead);
}