Example usage for java.util.zip Inflater setInput

List of usage examples for java.util.zip Inflater setInput

Introduction

In this page you can find the example usage for java.util.zip Inflater setInput.

Prototype

public void setInput(ByteBuffer input) 

Source Link

Document

Sets input data for decompression.

Usage

From source file:org.apache.uima.tools.docanalyzer.DBAnnotationViewerDialog.java

public void launchThatViewer(String xmi_id, TypeSystem typeSystem, final String[] aTypesToDisplay,
        boolean javaViewerRBisSelected, boolean javaViewerUCRBisSelected, boolean xmlRBisSelected,
        File styleMapFile, File viewerDirectory) {

    try {//from  ww  w . j a  v a 2s . com

        InputStream xmiDocument = this.xmiDAO.getXMI(xmi_id);

        // create a new CAS
        CAS cas = CasCreationUtils.createCas(Collections.EMPTY_LIST, typeSystem,
                UIMAFramework.getDefaultPerformanceTuningProperties());

        if (this.med1.isUmcompress()) {

            //Descomprime el XMI
            System.out.println("con compresin");

            //Create the decompressor and give it the data to compress
            Inflater decompressor = new Inflater();
            byte[] documentDataByteArray = IOUtils.toByteArray(xmiDocument);

            decompressor.setInput(documentDataByteArray);

            //Create an expandable byte array to hold the decompressed data
            ByteArrayOutputStream bos = new ByteArrayOutputStream(documentDataByteArray.length);

            //Decompress the data
            byte[] buf = new byte[1024];

            while (!decompressor.finished()) {

                int count = decompressor.inflate(buf);
                bos.write(buf, 0, count);
            }

            bos.close();

            //Get the decompressed data
            byte[] decompressedData = bos.toByteArray();

            XmiCasDeserializer.deserialize(new ByteArrayInputStream(decompressedData), cas, true);
        } else {

            System.out.println("sin compresin");
            XmlCasDeserializer.deserialize(xmiDocument, cas, true);
        }

        //get the specified view
        cas = cas.getView(this.defaultCasViewName);

        //launch appropriate viewer
        if (javaViewerRBisSelected || javaViewerUCRBisSelected) { // JMP

            // record preference for next time
            med1.setViewType(javaViewerRBisSelected ? "Java Viewer" : "JV User Colors");

            //create tree viewer component
            CasAnnotationViewer viewer = new CasAnnotationViewer();
            viewer.setDisplayedTypes(aTypesToDisplay);

            if (javaViewerUCRBisSelected)
                getColorsForTypesFromFile(viewer, styleMapFile);
            else
                viewer.setHiddenTypes(new String[] { "uima.cpm.FileLocation" });

            // launch viewer in a new dialog
            viewer.setCAS(cas);
            JDialog dialog = new JDialog(DBAnnotationViewerDialog.this,
                    "Annotation Results for " + xmi_id + " in " + inputDirPath); // JMP
            dialog.getContentPane().add(viewer);
            dialog.setSize(850, 630);
            dialog.pack();
            dialog.show();
        } else {

            CAS defaultView = cas.getView(CAS.NAME_DEFAULT_SOFA);

            if (defaultView.getDocumentText() == null) {
                displayError(
                        "The HTML and XML Viewers can only view the default text document, which was not found in this CAS.");
                return;
            }

            // generate inline XML
            File inlineXmlFile = new File(viewerDirectory, "inline.xml");
            String xmlAnnotations = new CasToInlineXml().generateXML(defaultView);
            FileOutputStream outStream = new FileOutputStream(inlineXmlFile);
            outStream.write(xmlAnnotations.getBytes("UTF-8"));
            outStream.close();

            if (xmlRBisSelected) // JMP passed in
            {
                // record preference for next time
                med1.setViewType("XML");

                BrowserUtil.openUrlInDefaultBrowser(inlineXmlFile.getAbsolutePath());
            } else
            // HTML view
            {
                med1.setViewType("HTML");
                // generate HTML view
                // first process style map if not done already
                if (!processedStyleMap) {
                    if (!styleMapFile.exists()) {
                        annotationViewGenerator.autoGenerateStyleMapFile(
                                promptForAE().getAnalysisEngineMetaData(), styleMapFile);
                    }
                    annotationViewGenerator.processStyleMap(styleMapFile);
                    processedStyleMap = true;
                }
                annotationViewGenerator.processDocument(inlineXmlFile);
                File genFile = new File(viewerDirectory, "index.html");
                // open in browser
                BrowserUtil.openUrlInDefaultBrowser(genFile.getAbsolutePath());
            }
        }

        // end LTV here

    } catch (Exception ex) {

        displayError(ex);
    }
}

From source file:org.zaproxy.zap.extension.ascanrulesAlpha.GitMetadata.java

/**
 * inflate the byte array, using the specified buffer size
 *
 * @param data the data to inflate//from  w  w  w  .  j  a  v  a2  s. c o m
 * @param buffersize the buffer size to use when inflating the data
 * @return the inflated data
 * @throws Exception
 */
protected byte[] inflate(byte[] data, int buffersize) throws Exception {
    Inflater inflater = new Inflater();
    inflater.setInput(data);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
    byte[] buffer = new byte[buffersize];
    while (!inflater.finished()) {
        int count = inflater.inflate(buffer);
        outputStream.write(buffer, 0, count);
    }
    outputStream.close();
    inflater.end();
    return outputStream.toByteArray();
}

From source file:edu.umass.cs.gigapaxos.SQLPaxosLogger.java

/**
 * @param buf/*from w ww . java2  s.  c om*/
 * @return Uncompressed form.
 * @throws IOException
 */
public static byte[] inflate(byte[] buf) throws IOException {
    if (!DB_COMPRESSION)
        return buf;
    Inflater inflator = new Inflater();
    inflator.setInput(buf);
    byte[] decompressed = new byte[buf.length];
    ByteArrayOutputStream baos = new ByteArrayOutputStream(buf.length);
    try {
        while (!inflator.finished()) {
            int count = inflator.inflate(decompressed);
            if (count == 0)
                break;
            baos.write(decompressed, 0, count);
        }
        baos.close();
        inflator.end();
    } catch (DataFormatException e) {
        PaxosManager.getLogger()
                .severe("DataFormatException while decompressing buffer of length " + buf.length);
        e.printStackTrace();
        return buf;
    }
    return baos.toByteArray();
}

From source file:edu.hawaii.soest.kilonalu.ctd.SeahorseSource.java

/**
 * A method that executes the streaming of data from the source to the RBNB
 * server after all configuration of settings, connections to hosts, and
 * thread initiatizing occurs.  This method contains the detailed code for 
 * streaming the data and interpreting the stream.
 *//*from  ww w  .  j a  va2  s.  co m*/
protected boolean execute() {
    logger.debug("SeahorseSource.execute() called.");
    // do not execute the stream if there is no connection
    if (!isConnected())
        return false;

    boolean failed = false;

    this.socketChannel = getSocketConnection();

    // while data are being sent, read them into the buffer
    try {
        // create four byte placeholders used to evaluate up to a four-byte 
        // window.  The FIFO layout looks like:
        //           -------------------------
        //   in ---> | One | Two |Three|Four |  ---> out
        //           -------------------------
        byte byteOne = 0x00, // set initial placeholder values
                byteTwo = 0x00, byteThree = 0x00, byteFour = 0x00;

        // define a byte array that will be used to manipulate the incoming bytes
        byte[] resultArray;
        String resultString;

        // Create a buffer that will store the result bytes as they are read
        ByteBuffer resultBuffer = ByteBuffer.allocate(getBufferSize());

        // create a byte buffer to store bytes from the TCP stream
        ByteBuffer buffer = ByteBuffer.allocateDirect(getBufferSize());

        this.rbnbChannelMap = new ChannelMap();
        this.channelIndex = 0;

        // initiate the session with the modem, test if is network registered
        this.command = this.MODEM_COMMAND_PREFIX + this.REGISTRATION_STATUS_COMMAND + this.MODEM_COMMAND_SUFFIX;
        this.sentCommand = queryInstrument(this.command);

        // allow time for the modem to respond
        streamingThread.sleep(this.SLEEP_INTERVAL);

        // while there are bytes to read from the socketChannel ...
        while (socketChannel.read(buffer) != -1 || buffer.position() > 0) {

            // prepare the buffer for reading
            buffer.flip();

            // while there are unread bytes in the ByteBuffer
            while (buffer.hasRemaining()) {
                byteOne = buffer.get();

                //logger.debug("b1: " + new String(Hex.encodeHex((new byte[]{byteOne})))   + "\t" + 
                //             "b2: " + new String(Hex.encodeHex((new byte[]{byteTwo})))   + "\t" + 
                //             "b3: " + new String(Hex.encodeHex((new byte[]{byteThree}))) + "\t" + 
                //             "b4: " + new String(Hex.encodeHex((new byte[]{byteFour})))  + "\t" +
                //             "result pos: "   + resultBuffer.position()                  + "\t" +
                //             "result rem: "   + resultBuffer.remaining()                 + "\t" +
                //             "result cnt: "   + resultByteCount                          + "\t" +
                //             "buffer pos: "   + buffer.position()                        + "\t" +
                //             "buffer rem: "   + buffer.remaining()                       + "\t" +
                //             "state: "        + state
                //);

                // Use a State Machine to process the byte stream.
                // Start building an rbnb frame for the entire sample, first by 
                // inserting a timestamp into the channelMap.  This time is merely
                // the time of insert into the data turbine, not the time of
                // observations of the measurements.  That time should be parsed out
                // of the sample in the Sink client code

                switch (state) {

                case 0:

                    // the network registration status should end in OK\r\n
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0A && byteTwo == 0x0D && byteThree == 0x4B && byteFour == 0x4F) {

                        logger.debug("Received the registration status result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the network registration status string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("Network Registration Result: " + resultString.trim());

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        resultArray = new byte[0];
                        resultString = "";
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        // send a request for the signal strength
                        this.command = this.MODEM_COMMAND_PREFIX + this.SIGNAL_STRENGTH_COMMAND
                                + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);
                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        state = 1;
                        break;

                    } else {
                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        break;
                    }

                case 1: // report the signal strength of the Iridium modem

                    // the signal strength status should end in OK\r\n
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0A && byteTwo == 0x0D && byteThree == 0x4B && byteFour == 0x4F) {

                        logger.debug("Received the signal strength result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the signal strength status string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("Signal Strength Result: " + resultString.trim());

                        int signalStrengthIndex = resultString.indexOf(this.SIGNAL_STRENGTH) + 5;

                        int signalStrength = new Integer(
                                resultString.substring(signalStrengthIndex, signalStrengthIndex + 1))
                                        .intValue();

                        // test if the signal strength is above the threshold
                        if (signalStrength > SIGNAL_THRESHOLD) {

                            resultBuffer.clear();
                            this.resultByteCount = 0;
                            resultArray = new byte[0];
                            resultString = "";
                            byteOne = 0x00;
                            byteTwo = 0x00;
                            byteThree = 0x00;
                            byteFour = 0x00;

                            state = 2;
                            break;

                            // the signal strength is too low, check again
                        } else {

                            resultBuffer.clear();
                            this.resultByteCount = 0;
                            resultArray = new byte[0];
                            resultString = "";
                            byteOne = 0x00;
                            byteTwo = 0x00;
                            byteThree = 0x00;
                            byteFour = 0x00;

                            // resend a request for the signal strength
                            this.command = this.MODEM_COMMAND_PREFIX + this.SIGNAL_STRENGTH_COMMAND
                                    + this.MODEM_COMMAND_SUFFIX;
                            this.sentCommand = queryInstrument(this.command);
                            // allow time for the modem to respond
                            streamingThread.sleep(this.SLEEP_INTERVAL);

                            state = 1;
                            break;

                        }

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;
                    }

                case 2: // handle the RING command from the instrument

                    // listen for the RING command 
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x47 && byteTwo == 0x4E && byteThree == 0x49 && byteFour == 0x52) {

                        logger.debug("Received the RING command.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        resultArray = new byte[0];
                        resultString = "";
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        // answer the call
                        this.command = this.MODEM_COMMAND_PREFIX + this.ANSWER_COMMAND
                                + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);
                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        state = 3;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 3: // acknowledge the connection

                    // the ready status string should end in READY\r
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0D && byteTwo == 0x59 && byteThree == 0x44 && byteFour == 0x41) {

                        logger.debug("Received the ready status result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the connect rate and ready status string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");

                        // test the connect rate
                        logger.debug("Result from ATA: " + resultString);

                        if (resultString.indexOf(this.CONNECT_RATE) > 0) {
                            logger.debug("Connect Rate Result: " + this.CONNECT_RATE);

                            // test the ready status
                            if (resultString.indexOf(this.READY_STATUS) > 0) {
                                logger.debug("Connect Rate Result: " + this.READY_STATUS);

                                resultBuffer.clear();
                                this.resultByteCount = 0;
                                resultArray = new byte[0];
                                resultString = "";
                                byteOne = 0x00;
                                byteTwo = 0x00;
                                byteThree = 0x00;
                                byteFour = 0x00;

                                // acknowledge the ready status
                                this.command = this.ACKNOWLEDGE_COMMAND + this.MODEM_COMMAND_SUFFIX;
                                this.sentCommand = queryInstrument(this.command);

                                // allow time for the modem to receive the ACK
                                streamingThread.sleep(this.SLEEP_INTERVAL);

                                // query the instrument id
                                this.command = this.ID_COMMAND + this.MODEM_COMMAND_SUFFIX;
                                this.sentCommand = queryInstrument(this.command);

                                // allow time for the modem to respond
                                streamingThread.sleep(this.SLEEP_INTERVAL);

                                state = 4;
                                break;

                            } else {
                                logger.debug("The ready status differs from: " + this.READY_STATUS);

                                // throw an exception here?
                                break;
                            }

                        } else {
                            logger.debug("The connect rate differs from: " + this.CONNECT_RATE);

                            // throw an exception here?
                            break;
                        }

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 4: // get the instrument id

                    // the instrument ID string should end in \r
                    if (byteOne == 0x0D) {

                        logger.debug("Received the instrument ID result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the instrument ID string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("Seahorse Instrument ID: " + resultString.trim());

                        // set the platformID variable
                        this.platformID = resultString.substring(0, resultString.length() - 1);

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        resultArray = new byte[0];
                        resultString = "";
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        // query the battery voltage
                        this.command = this.BATTERY_VOLTAGE_COMMAND + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        state = 5;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 5: // get the seahorse battery voltage

                    // the battery voltage string should end in \r
                    if (byteOne == 0x0D) {

                        logger.debug("Received the instrument battery voltage result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the battery voltage string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("Seahorse Battery Voltage: " + resultString.trim());

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        resultArray = new byte[0];
                        resultString = "";
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        // query the GPS location
                        this.command = this.GPRMC_COMMAND + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        state = 6;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 6:

                    // the GPRMC string should end in END\r
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0D && byteTwo == 0x44 && byteThree == 0x4E && byteFour == 0x45) {

                        logger.debug("Received the GPRMS result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the GPRMC string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("Seahorse GPRMC string: " + resultString.trim());

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        resultArray = new byte[0];
                        resultString = "";
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        // query the file name for transfer
                        this.command = this.FILENAME_COMMAND + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        state = 7;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 7:

                    // the file name string should end in .Z\r
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0D && byteTwo == 0x5A && byteThree == 0x2E) {

                        logger.debug("Received the file name result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the file name string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("File name result: " + resultString.trim());

                        resultString = resultString.trim();
                        int fileNameIndex = resultString.indexOf(this.FILENAME_PREFIX);

                        //extract just the filename from the result (excise the "FILE=")
                        this.fileNameToDownload = resultString.substring(
                                (fileNameIndex + (this.FILENAME_PREFIX).length()), resultString.length());

                        logger.debug("File name to download: " + this.fileNameToDownload);

                        // test to see if the GFN command returns FILES=NONE
                        if (!(resultString.indexOf(this.END_OF_FILES) > 0)) {

                            // there is a file to download. parse the file name,
                            // get the number of blocks to transfer
                            this.command = this.NUMBER_OF_BLOCKS_COMMAND + this.MODEM_COMMAND_SUFFIX;
                            this.sentCommand = queryInstrument(this.command);

                            // allow time for the modem to respond
                            streamingThread.sleep(this.SLEEP_INTERVAL);

                            resultBuffer.clear();
                            this.resultByteCount = 0;
                            resultArray = new byte[0];
                            resultString = "";
                            byteOne = 0x00;
                            byteTwo = 0x00;
                            byteThree = 0x00;
                            byteFour = 0x00;

                            state = 8;
                            break;

                        } else {

                            // We have downloaded all files. Parse the data string,
                            // build the channel map, and flush the data to the Dataturbine
                            // by iterating through the data matrix.  The metadata and
                            // ASCII data strings are flushed once with the first matrix
                            // row.

                            // Parse the data file, not the cast file.
                            try {

                                // parse the CTD data file
                                this.ctdParser = new CTDParser(this.dataFileString);

                                // convert the raw frequencies and voltages to engineering
                                // units and return the data as a matrix
                                CTDConverter ctdConverter = new CTDConverter(this.ctdParser);
                                ctdConverter.convert();
                                RealMatrix convertedDataMatrix = ctdConverter.getConvertedDataValuesMatrix();

                                // Register the data and metadata channels;
                                failed = register();

                                if (!failed) {
                                    // format the first sample date and use it as the first insert
                                    // date.  Add the sampleInterval on each iteration to insert
                                    // subsequent data rows.  Sample interval is by default 
                                    // 4 scans/second for the CTD.
                                    DATE_FORMAT.setTimeZone(TZ);
                                    this.sampleDateTime = Calendar.getInstance();
                                    this.sampleDateTime
                                            .setTime(DATE_FORMAT.parse(ctdParser.getFirstSampleTime()));

                                    for (int row = 0; row < convertedDataMatrix.getRowDimension(); row++) {

                                        // Only insert the metadata fields and full ASCII text strings
                                        // with the first row of data
                                        if (row == 0) {
                                            // Add the samplingMode data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("samplingMode");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getSamplingMode());

                                            // Add the firstSampleTime data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("firstSampleTime");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getFirstSampleTime());

                                            // Add the fileName data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("fileName");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getFileName());

                                            // Add the temperatureSerialNumber data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureSerialNumber");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getTemperatureSerialNumber());

                                            // Add the conductivitySerialNumber data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivitySerialNumber");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getConductivitySerialNumber());

                                            // Add the systemUpLoadTime data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("systemUpLoadTime");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getSystemUpLoadTime());

                                            // Add the cruiseInformation data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("cruiseInformation");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getCruiseInformation());

                                            // Add the stationInformation data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("stationInformation");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getStationInformation());

                                            // Add the shipInformation data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("shipInformation");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getShipInformation());

                                            // Add the chiefScientist data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("chiefScientist");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getChiefScientist());

                                            // Add the organization data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("organization");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getOrganization());

                                            // Add the areaOfOperation data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("areaOfOperation");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getAreaOfOperation());

                                            // Add the instrumentPackage data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("instrumentPackage");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getInstrumentPackage());

                                            // Add the mooringNumber data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("mooringNumber");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getMooringNumber());

                                            // Add the instrumentLatitude data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("instrumentLatitude");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getInstrumentLatitude() });

                                            // Add the instrumentLongitude data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("instrumentLongitude");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getInstrumentLongitude() });

                                            // Add the depthSounding data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("depthSounding");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getDepthSounding() });

                                            // Add the profileNumber data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("profileNumber");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getProfileNumber());

                                            // Add the profileDirection data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("profileDirection");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getProfileDirection());

                                            // Add the deploymentNotes data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("deploymentNotes");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getDeploymentNotes());

                                            // Add the mainBatteryVoltage data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("mainBatteryVoltage");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getMainBatteryVoltage() });

                                            // Add the lithiumBatteryVoltage data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("lithiumBatteryVoltage");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getLithiumBatteryVoltage() });

                                            // Add the operatingCurrent data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("operatingCurrent");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getOperatingCurrent() });

                                            // Add the pumpCurrent data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("pumpCurrent");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser.getPumpCurrent() });

                                            // Add the channels01ExternalCurrent data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("channels01ExternalCurrent");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getChannels01ExternalCurrent() });

                                            // Add the channels23ExternalCurrent data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("channels23ExternalCurrent");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getChannels23ExternalCurrent() });

                                            // Add the loggingStatus data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("loggingStatus");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getLoggingStatus());

                                            // Add the numberOfScansToAverage data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("numberOfScansToAverage");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getNumberOfScansToAverage() });

                                            // Add the numberOfSamples data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("numberOfSamples");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getNumberOfSamples() });

                                            // Add the numberOfAvailableSamples data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("numberOfAvailableSamples");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getNumberOfAvailableSamples() });

                                            // Add the sampleInterval data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("sampleInterval");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getSampleInterval() });

                                            // Add the measurementsPerSample data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("measurementsPerSample");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getMeasurementsPerSample() });

                                            // Add the transmitRealtime data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("transmitRealtime");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getTransmitRealtime());

                                            // Add the numberOfCasts data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("numberOfCasts");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getNumberOfCasts() });

                                            // Add the minimumConductivityFrequency data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("minimumConductivityFrequency");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex, new int[] {
                                                    this.ctdParser.getMinimumConductivityFrequency() });

                                            // Add the pumpDelay data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("pumpDelay");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsInt32(this.channelIndex,
                                                    new int[] { this.ctdParser.getPumpDelay() });

                                            // Add the automaticLogging data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("automaticLogging");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getAutomaticLogging());

                                            // Add the ignoreMagneticSwitch data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("ignoreMagneticSwitch");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getIgnoreMagneticSwitch());

                                            // Add the batteryType data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("batteryType");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getBatteryType());

                                            // Add the batteryCutoff data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("batteryCutoff");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getBatteryCutoff());

                                            // Add the pressureSensorType data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("pressureSensorType");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getPressureSensorType());

                                            // Add the pressureSensorRange data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("pressureSensorRange");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getPressureSensorRange());

                                            // Add the sbe38TemperatureSensor data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("sbe38TemperatureSensor");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getSbe38TemperatureSensor());

                                            // Add the gasTensionDevice data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("gasTensionDevice");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getGasTensionDevice());

                                            // Add the externalVoltageChannelZero data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("externalVoltageChannelZero");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getExternalVoltageChannelZero());

                                            // Add the externalVoltageChannelOne data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("externalVoltageChannelOne");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getExternalVoltageChannelOne());

                                            // Add the externalVoltageChannelTwo data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("externalVoltageChannelTwo");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getExternalVoltageChannelTwo());

                                            // Add the externalVoltageChannelThree data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("externalVoltageChannelThree");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getExternalVoltageChannelThree());

                                            // Add the echoCommands data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("echoCommands");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getEchoCommands());

                                            // Add the outputFormat data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("outputFormat");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getOutputFormat());

                                            // Add the temperatureCalibrationDate data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureCalibrationDate");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getTemperatureCalibrationDate());

                                            // Add the temperatureCoefficientTA0 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureCoefficientTA0");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getTemperatureCoefficientTA0() });

                                            // Add the temperatureCoefficientTA1 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureCoefficientTA1");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getTemperatureCoefficientTA1() });

                                            // Add the temperatureCoefficientTA2 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureCoefficientTA2");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getTemperatureCoefficientTA2() });

                                            // Add the temperatureCoefficientTA3 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureCoefficientTA3");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getTemperatureCoefficientTA3() });

                                            // Add the temperatureOffsetCoefficient data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("temperatureOffsetCoefficient");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getTemperatureOffsetCoefficient() });

                                            // Add the conductivityCalibrationDate data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCalibrationDate");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getConductivityCalibrationDate());

                                            // Add the conductivityCoefficientG data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientG");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientG() });

                                            // Add the conductivityCoefficientH data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientH");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientH() });

                                            // Add the conductivityCoefficientI data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientI");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientI() });

                                            // Add the conductivityCoefficientJ data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientJ");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientJ() });

                                            // Add the conductivityCoefficientCF0 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientCF0");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientCF0() });

                                            // Add the conductivityCoefficientCPCOR data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientCPCOR");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientCPCOR() });

                                            // Add the conductivityCoefficientCTCOR data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientCTCOR");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getConductivityCoefficientCTCOR() });

                                            // Add the conductivityCoefficientCSLOPE data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("conductivityCoefficientCSLOPE");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] { this.ctdParser
                                                            .getConductivityCoefficientCSLOPE() });

                                            // Add the pressureSerialNumber data to the channel map
                                            this.channelIndex = this.rbnbChannelMap.Add("pressureSerialNumber");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.ctdParser.getPressureSerialNumber());

                                            // Add the pressureCoefficientPA0 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPA0");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPA0() });

                                            // Add the pressureCoefficientPA1 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPA1");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPA1() });

                                            // Add the pressureCoefficientPA2 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPA2");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPA2() });

                                            // Add the pressureCoefficientPTCA0 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTCA0");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTCA0() });

                                            // Add the pressureCoefficientPTCA1 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTCA1");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTCA1() });

                                            // Add the pressureCoefficientPTCA2 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTCA2");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTCA2() });

                                            // Add the pressureCoefficientPTCB0 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTCB0");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTCB0() });

                                            // Add the pressureCoefficientPTCB1 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTCB1");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTCB1() });

                                            // Add the pressureCoefficientPTCB2 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTCB2");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTCB2() });

                                            // Add the pressureCoefficientPTEMPA0 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTEMPA0");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTEMPA0() });

                                            // Add the pressureCoefficientPTEMPA1 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTEMPA1");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTEMPA1() });

                                            // Add the pressureCoefficientPTEMPA2 data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureCoefficientPTEMPA2");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureCoefficientPTEMPA2() });

                                            // Add the pressureOffsetCoefficient data to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add("pressureOffsetCoefficient");
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            this.ctdParser.getPressureOffsetCoefficient() });

                                            // Insert the file into the channel map. 
                                            this.channelIndex = this.rbnbChannelMap.Add(this.rbnbChannelName);
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.dataFileString);

                                            this.channelIndex = this.rbnbChannelMap.Add("ASCIICastData");
                                            this.rbnbChannelMap.PutMime(this.channelIndex, "text/plain");
                                            this.rbnbChannelMap.PutDataAsString(this.channelIndex,
                                                    this.castFileString);

                                        }

                                        // Add in the matrix data row to the map here
                                        List<String> variableNames = ctdParser.getDataVariableNames();
                                        List<String> variableUnits = ctdParser.getDataVariableUnits();

                                        // iterate through the variable names and add them to
                                        // the channel map.
                                        for (int variableIndex = 0; variableIndex < variableNames
                                                .size(); variableIndex++) {

                                            //  Add the variable name to the channel map
                                            this.channelIndex = this.rbnbChannelMap
                                                    .Add(variableNames.get(variableIndex));
                                            // The matrix is a double array, so set the data type below
                                            this.rbnbChannelMap.PutMime(this.channelIndex,
                                                    "application/octet-stream");
                                            // add the data to the map from the [row,column] of the
                                            // matrix (row is from the outer for loop)
                                            this.rbnbChannelMap.PutDataAsFloat64(this.channelIndex,
                                                    new double[] {
                                                            convertedDataMatrix.getEntry(row, variableIndex) });

                                        }

                                        // Flush the channel map to the RBNB
                                        double sampleTimeAsSecondsSinceEpoch = (double) (this.sampleDateTime
                                                .getTimeInMillis() / 1000);
                                        this.rbnbChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d);
                                        getSource().Flush(this.rbnbChannelMap);

                                        logger.info("Flushed data to the DataTurbine.");
                                        this.rbnbChannelMap.Clear();

                                        // samples are taken 4x per second, so increment the
                                        // sample time by 250 milliseconds for the next insert                     
                                        this.sampleDateTime.add(Calendar.MILLISECOND, 250);

                                    } // end for loop 

                                } //  end if !failed

                            } catch (Exception e) {
                                logger.debug("Failed to parse the CTD data file: " + e.getMessage());

                            }

                            // there are no more files to read. close the Tx session.
                            this.command = this.CLOSE_TRANSFER_SESSION_COMMAND + this.MODEM_COMMAND_SUFFIX;
                            this.sentCommand = queryInstrument(this.command);

                            // allow time for the modem to respond
                            streamingThread.sleep(this.SLEEP_INTERVAL);

                            // clean up
                            resultBuffer.clear();
                            this.resultByteCount = 0;
                            resultArray = new byte[0];
                            resultString = "";
                            byteOne = 0x00;
                            byteTwo = 0x00;
                            byteThree = 0x00;
                            byteFour = 0x00;

                            state = 10;
                            break;

                        }

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 8:

                    // the number of blocks string should end in \r
                    if (byteOne == 0x0D) {

                        logger.debug("Received the number of blocks result.");

                        this.resultByteCount++; // add the last byte found to the count

                        // add the last byte found to the result buffer
                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);

                        } else {
                            resultBuffer.compact();
                            resultBuffer.put(byteOne);

                        }

                        // report the number of blocks string
                        resultArray = new byte[this.resultByteCount];
                        resultBuffer.flip();
                        resultBuffer.get(resultArray);
                        resultString = new String(resultArray, "US-ASCII");
                        logger.debug("Number of bytes reported: " + resultString.trim());

                        int numberOfBlocksIndex = resultString.indexOf(this.BLOCKSIZE_PREFIX);

                        // If 'BLOCKSIZE=' is not found, set the index to 0
                        if (numberOfBlocksIndex == -1) {
                            numberOfBlocksIndex = 0;

                        }

                        resultString = resultString.substring(
                                (numberOfBlocksIndex + (this.BLOCKSIZE_PREFIX).length()),
                                resultString.length());

                        // convert the string to an integer
                        try {
                            this.numberOfBlocks = new Integer(resultString.trim()).intValue();
                            logger.debug("Number of bytes to download: " + this.numberOfBlocks);

                        } catch (java.lang.NumberFormatException nfe) {
                            failed = true;
                            nfe.printStackTrace();
                            logger.debug("Failed to convert returned string value "
                                    + "to an integer value.  The returned string is: " + this.numberOfBlocks);

                        }

                        // test to see if the GNB command returns DONE\r
                        if (!(resultString.indexOf(this.TRANSFER_COMPLETE) > 0)) {

                            // there are bytes to transfer. send the transfer command

                            this.command = this.TRANSFER_BLOCKS_COMMAND + this.MODEM_COMMAND_SUFFIX;
                            this.sentCommand = queryInstrument(this.command);

                            // allow time for the modem to respond
                            streamingThread.sleep(this.SLEEP_INTERVAL);

                            //resultBuffer.clear(); dont clear the buffer
                            this.resultByteCount = 0;
                            resultArray = new byte[0];
                            resultString = "";
                            byteOne = 0x00;
                            byteTwo = 0x00;
                            byteThree = 0x00;
                            byteFour = 0x00;

                            state = 9;
                            break;

                        } else {

                            // there are no more bytes to transfer.  

                            // Decompress the file, which is under zlib compression.  
                            Inflater inflater = new Inflater();
                            inflater.setInput(resultBuffer.array());
                            byte[] output = new byte[resultBuffer.capacity()];

                            int numDecompressed = inflater.inflate(output);

                            // set the appropriate string variable
                            if (this.fileNameToDownload.indexOf(DATA_FILE_PREFIX) > 0) {
                                this.dataFileString = new String(output);

                                //report the file contents to the log
                                logger.debug("File " + this.fileNameToDownload + ": ");
                                logger.debug(this.dataFileString);

                            } else {
                                this.castFileString = new String(output);

                                //report the file contents to the log
                                logger.debug("File " + this.fileNameToDownload + ": ");
                                logger.debug(this.castFileString);

                            }

                            // Ask for the next file.
                            this.command = this.FILENAME_COMMAND + this.MODEM_COMMAND_SUFFIX;
                            this.sentCommand = queryInstrument(this.command);

                            // allow time for the modem to respond
                            streamingThread.sleep(this.SLEEP_INTERVAL);

                            //resultBuffer.clear(); dont clear the buffer
                            this.resultByteCount = 0;
                            resultArray = new byte[0];
                            resultString = "";
                            byteOne = 0x00;
                            byteTwo = 0x00;
                            byteThree = 0x00;
                            byteFour = 0x00;

                            state = 7; //back to the file name state
                            break;

                        }

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 9:

                    // transfer up to the reported number of bytes
                    if (this.resultByteCount == this.numberOfBlocks) {

                        // we have downloaded the reported bytes. get the next section.
                        // get the number of blocks to transfer
                        this.command = this.NUMBER_OF_BLOCKS_COMMAND + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        //resultBuffer.clear();
                        this.resultByteCount = 0;
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        state = 8;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 10:

                    // the response from the modem should end in BYE\r
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0D && byteTwo == 0x45 && byteThree == 0x59 && byteFour == 0x42) {

                        logger.debug("Received the BYE command.");

                        // continue to disconnect. send the escape sequence
                        this.command = this.ESCAPE_SEQUENCE_COMMAND + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        state = 11;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 11:

                    // the response from the modem should end in OK\r\n
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0D && byteTwo == 0x0A && byteThree == 0x4B && byteFour == 0x4F) {

                        // now hang up.
                        this.command = this.MODEM_COMMAND_PREFIX + this.HANGUP_COMMAND
                                + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        state = 12;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                case 12:

                    // the response from the modem should end in OK\r\n
                    // note bytes are in reverse order in the FIFO window
                    if (byteOne == 0x0D && byteTwo == 0x0A && byteThree == 0x4B && byteFour == 0x4F) {

                        // we are done. re-test if is network registered
                        this.command = this.MODEM_COMMAND_PREFIX + this.REGISTRATION_STATUS_COMMAND
                                + this.MODEM_COMMAND_SUFFIX;
                        this.sentCommand = queryInstrument(this.command);

                        // allow time for the modem to respond
                        streamingThread.sleep(this.SLEEP_INTERVAL);

                        resultBuffer.clear();
                        this.resultByteCount = 0;
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;

                        state = 0;
                        break;

                    } else {

                        // still in the middle of the result, keep adding bytes
                        this.resultByteCount++; // add each byte found

                        if (resultBuffer.remaining() > 0) {
                            resultBuffer.put(byteOne);
                        } else {
                            resultBuffer.compact();
                            logger.debug("Compacting resultBuffer ...");
                            resultBuffer.put(byteOne);

                        }

                        break;

                    }

                } // end switch statement

                // shift the bytes in the FIFO window
                byteFour = byteThree;
                byteThree = byteTwo;
                byteTwo = byteOne;

            } //end while (more unread bytes)

            // prepare the buffer to read in more bytes from the stream
            buffer.compact();

        } // end while (more socketChannel bytes to read)
        socketChannel.close();

    } catch (IOException e) {
        // handle exceptions
        // In the event of an i/o exception, log the exception, and allow execute()
        // to return false, which will prompt a retry.
        failed = true;
        e.printStackTrace();
        return !failed;

    } catch (java.lang.InterruptedException ine) {
        failed = true;
        ine.printStackTrace();
        return !failed;

    } catch (java.util.zip.DataFormatException dfe) {
        failed = true;
        dfe.printStackTrace();
        return !failed;
    }

    return !failed;
}