private InputStream getCorrectInputStream() throws IOException {
        // if in cached mode use the tmp file
        if (isCached) {
            if (tempFile != null) {
                // initiate a new input stream in needed
                if (fileInputStream == null) {
                    fileInputStream = new FileInputStream(tempFile);
                }
                return fileInputStream;
            }
        } else {
            if (byteArrayOutputStream != null) {
                if (byteArrayInputStream == null) {
                    byteArrayInputStream =
                            new ByteArrayInputStream(
                                    byteArrayOutputStream.toByteArray());
                }
                return byteArrayInputStream;
            }
        }
        return null;
    }