ByteArrayOutputStream out = new ByteArrayOutputStream();
int numBytesRead;
byte[] data = new byte[line.getBufferSize() / 5];
// Begin audio capture.
line.start();
// Here, stopped is a global boolean set by another thread.
while(out.size() < bytesRequired) {
// Read the next chunk of data from the TargetDataLine.
numBytesRead = line.read(data, 0, data.length);