FileOutputStream fos = new FileOutputStream(file);
GeneralFileOutputStream fos = FileFactory.newFileOutputStream(file);
    public static int store(Context context, InputStream is)            throws SQLException, IOException    {        // Create internal ID        String id = Utils.generateKey();        // Create a deleted bitstream row, using a separate DB connection        TableRow bitstream;        Context tempContext = null;        try        {            tempContext = new Context();            bitstream = DatabaseManager.create(tempContext, "Bitstream");            bitstream.setColumn("deleted", true);            bitstream.setColumn("internal_id", id);            /*             * Set the store number of the new bitstream If you want to use some             * other method of working out where to put a new bitstream, here's             * where it should go             */            bitstream.setColumn("store_number", incoming);            DatabaseManager.update(tempContext, bitstream);            tempContext.complete();        }        catch (SQLException sqle)        {            if (tempContext != null)            {                tempContext.abort();            }            throw sqle;        }        // Where on the file system will this new bitstream go?        File file = getFile(bitstream);        // Make the parent dirs if necessary        File parent = file.getParentFile();        if (!parent.exists())        {            parent.mkdirs();        }        //Create the corresponding file and open it        file.createNewFile();        FileOutputStream fos = new FileOutputStream(file);        // Read through a digest input stream that will work out the MD5        DigestInputStream dis = null;        try        {            dis = new DigestInputStream(is, MessageDigest.getInstance("MD5"));        }        // Should never happen        catch (NoSuchAlgorithmException nsae)        {            log.warn("Caught NoSuchAlgorithmException", nsae);        }        Utils.bufferedCopy(dis, fos);        fos.close();        is.close();        if ("oracle".equals(ConfigurationManager.getProperty("db.name")))        {            bitstream.setColumn("size_bytes", (int) file.length());        }        else        {            // postgres default            bitstream.setColumn("size", (int) file.length());        }        bitstream.setColumn("checksum", Utils.toHex(dis.getMessageDigest()                .digest()));        bitstream.setColumn("checksum_algorithm", "MD5");        bitstream.setColumn("deleted", false);        DatabaseManager.update(context, bitstream);        int bitstream_id = bitstream.getIntColumn("bitstream_id");        if (log.isDebugEnabled())        {            log.debug("Stored bitstream " + bitstream_id + " in file "                    + file.getAbsolutePath());        }        return bitstream_id;    }