sinterface Capturer { void stop(); byte[] getPCM(); } static Capturer captureAudioFromLine2(DataLine line, AudioFormat format) ctex { if (!line instanceof TargetDataLine) fail(getClassName(line)); final TargetDataLine tdl = cast line; tdl.open(format); tdl.start(); ret new Capturer { volatile bool stopped; new ByteArrayOutputStream baos; public void stop() { stopped = true; } { thread "Audio Capture" { try { int total = 0, n; byte[] buf = new byte[1024]; while (!stopped && licensed() && (n = tdl.read(buf, 0, min(l(buf), bytesWanted-total))) > 0) { total += n; baos.write(buf, 0, n); print("Bytes read from line: " + total); } } finally { tdl.close(); } } } public byte[] getPCM() { ret baos.toByteArray(); } }; }