/** * Creates an output stream to where the artifact content can be written to. * * <p>If the artifact already exists and the artifact is not a link a <code> * ArtifactAlreadyExistsException</code> will be thrown. If the directory doesn't exists, it will * be created. * * @exception IOException if an IO error occurs. * @exception NullArgumentException if the artifact argument is null. * @exception ArtifactAlreadyExistsException if the artifact already exists in the cache and the * artifact is not a link. */ public OutputStream createOutputStream(Artifact artifact) throws NullArgumentException, ArtifactAlreadyExistsException, IOException { if (null == artifact) { throw new NullArgumentException("artifact"); } ResourceHost any = findAnyPresence(artifact); String scheme = artifact.getScheme(); boolean flag = !"link".equals(scheme); if ((any != null) && flag) { throw new ArtifactAlreadyExistsException("Artifact found on server.", artifact); } String path = m_resolver.resolvePath(artifact); File destination = new File(m_cacheDir, path); if (destination.exists() && flag) { throw new ArtifactAlreadyExistsException("Artifact found in cache.", artifact); } File parentDir = destination.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); } return new FileOutputStream(destination); }