private static void writeResourceToFile(
        String resourceName, File file) throws IOException
    {
        if (file == null)
        {
            throw new NullPointerException("Target file may not be null");
        }
        if (file.exists())
        {
            throw new IllegalArgumentException(
                "Target file already exists: "+file);
        }
        InputStream inputStream = 
            LibUtils.class.getResourceAsStream(resourceName);
        if (inputStream == null)
        {
            throw new IOException(
                "No resource found with name '"+resourceName+"'");
        }
        OutputStream outputStream = null;
        try
        {
            outputStream = new FileOutputStream(file);
            byte[] buffer = new byte[32768];
            while (true)
            {
                int read = inputStream.read(buffer);
                if (read < 0)
                {
                    break;
                }
                outputStream.write(buffer, 0, read);    
            }
            outputStream.flush();
        }
        finally 
        {
            if (outputStream != null)
            {
                try
                {
                    outputStream.close();
                }
                catch (IOException e)
                {
                    logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
            try
            {
                inputStream.close();
            }
            catch (IOException e)
            {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }