Windows issue with buffer write and FileOutputStream

I have an override of readReplyFromWebserver (from juce_OnlineUnlockStatus). It reads the reply from the webserver and then uses Blowfish to encrypt the response (in the HeapBlock buffer) and then writes this to file. This works perfectly on OSX, however it fails miserably on Windows. What could I be doing wrong?

            // Encrypt (
            // contentLength is taken from stream->getTotalLength(); as in the readReplyFromWebserver function.
            // bufferSize is 0x8000 (or 32768 in int)
            const String encryptionKey = "123";
            BlowFish bf (encryptionKey.toUTF8(), (int) encryptionKey.getNumBytesAsUTF8());
            bf.encrypt(buffer.get(), contentLength, bufferSize);

            // Write encrypted buffer to file
            outStream.setPosition (0);
            outStream.truncate();
            outStream.write(buffer.get(), contentLength);

I managed to resolve this by using a variable called downloaded (available in readReplyFromWebserver and which represents the actual bytes downloaded). In my case (or for Windows it seems), the function getTotalLength returns a -1, which doesn’t affect reading the stream however seems odd since there is actually data in the stream.