public void transmitTextFile(final File file, final LoggedDataOutputStream dos) throws IOException {
        if ((file == null) || !file.exists()) {
            throw new IllegalArgumentException("File is either null or " + "does not exist. Cannot transmit.");
        }

        File fileToSend = file;

        final TransmitTextFilePreprocessor transmitTextFilePreprocessor = getTransmitTextFilePreprocessor();

        if (transmitTextFilePreprocessor != null) {
            fileToSend = transmitTextFilePreprocessor.getPreprocessedTextFile(file);
        }

        BufferedInputStream bis = null;
        try {
            // first write the length of the file
            long length = fileToSend.length();
            dos.writeBytes(getLengthString(length), "US-ASCII");

            bis = new BufferedInputStream(new FileInputStream(fileToSend));
            // now transmit the file itself
            final byte[] chunk = new byte[CHUNK_SIZE];
            while (length > 0) {
                final int bytesToRead = (length >= CHUNK_SIZE) ? CHUNK_SIZE : (int) length;
                final int count = bis.read(chunk, 0, bytesToRead);
                if (count == -1) {
                    throw new IOException("Unexpected end of stream from " + fileToSend + ".");
                }
                length -= count;
                dos.write(chunk, 0, count);
            }
            dos.flush();
        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (final IOException ex) {
                    // ignore
                }
            }
            if (transmitTextFilePreprocessor != null) {
                transmitTextFilePreprocessor.cleanup(fileToSend);
            }
        }
    }