/** * @return a file reference for the given id, checking for existence based on the given flag. */ protected File getFileForId(String id, boolean shouldExist) { BigInteger idValue = null; try { idValue = new BigInteger(id); } catch (NumberFormatException nfe) { throw new ContentStorageException("Illegal ID value, only positive numbers are supported: " + id, nfe); } File path = converter.getPathForId(idValue); File file = new File(rootFolder, path.getPath()); if (shouldExist != file.exists()) { if (shouldExist) { throw new ContentNotFoundException("Content with id: " + id + " was not found (path: " + file.toString() + ")"); } else { throw new ContentNotFoundException("Content with id: " + id + " already exists."); } } return file; }