public void run() {

        // Ensure we have a compatible line for our format.
        AudioFormat format = Utils.getFormat();
        TargetDataLine line = this.getAudioLine(format);
        if (null == line) {
            System.err.println("Unable to get line");
            return;
        }

        // Record!
        ByteArrayOutputStream first_100ms_bytes = new ByteArrayOutputStream();
        byte[] data = new byte[Utils.CHUNK_OF_10MS];

        int numBytesRead = 0;
        int totalBytesRead = 0;
        boolean first100Analyzed = false;

        line.start();
        while (running) {
            // System.out.println("listening");
            if ((numBytesRead = line.read(data, 0, Utils.CHUNK_OF_10MS)) == -1) {
                break;
            }
            totalBytesRead += numBytesRead;
            System.out.println("totalBytesRead: " + totalBytesRead);

            baos.write(data, 0, numBytesRead);

            // Selectively write the first 100ms to this different buffer
            if (first_100ms_bytes.size() < Utils.CHUNK_OF_100_MS) {
                first_100ms_bytes.write(data, 0, numBytesRead);
            } else {
                if (!first100Analyzed) {
                    processFirst100ms(first_100ms_bytes);
                    first100Analyzed = true;
                }
            }

        }

        // we reached the end of the stream. stop and close the line.
        line.stop();
        line.close();
        line = null;

        System.out.println("Line stopped, closed, and nulled");

        // stop and close the output stream
        try {
            baos.flush();
            baos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        this.thread = null;
    }