@Override
  public OutputStream getOutputStream(IArtifactDescriptor descriptor) throws ProvisionException {
    if (descriptor == null) {
      throw new NullPointerException();
    } else if (!(descriptor instanceof ModuleArtifactDescriptor)) {
      throw new IllegalArgumentException("Descriptor must have been created by this repository");
    }

    String classifier = descriptor.getProperty(RepositoryLayoutHelper.PROP_CLASSIFIER);

    // look up storage location
    File storageLocation = artifactsMap.addToAutomaticLocation(classifier);

    // TODO download.size/artifact.size is not set in the descriptor for product binaries -> compute
    // while streaming

    internalAddDescriptor(descriptor);
    storeOrProvisioningException();

    try {
      return new FileOutputStream(storageLocation);
    } catch (FileNotFoundException e) {
      throw new ProvisionException(
          "Failed to write artifact " + descriptor.getArtifactKey() + " to " + storageLocation, e);
    }
  }
  public static ModuleArtifactRepository createInstance(
      IProvisioningAgent agent, File repositoryDir) throws ProvisionException {
    ModuleArtifactRepository newInstance =
        new ModuleArtifactRepository(
            agent, repositoryDir.toURI(), createArtifactLocationMap(repositoryDir));

    // make sure p2artifacts.xml exists
    newInstance.storeOrProvisioningException();
    return newInstance;
  }