private OutputStream getCorrectOutputStream(int optionalPresizing) throws IOException {
        if (isCached) {
            // create the tmp file if not initiated.
            if (tempFile == null) {
                createTempFile();
            }
            // create the new file stream
            if (fileOutputStream == null) {
                fileOutputStream = new FileOutputStream(tempFile.getAbsolutePath(), true);
            }
            return fileOutputStream;
        } else {
            // create the byte array if not initiated
            if (byteArrayOutputStream == null) {
                byteArrayOutputStream = new ByteArrayOutputStream(optionalPresizing);
            }
            return byteArrayOutputStream;
        }
    }