/**
   * Remove a file from an item
   *
   * @param context current DSpace context
   * @param item Item where file should be removed from
   * @param bitstreamID The id of bitstream representing the file to remove
   * @return Status or error flag which will be processed by UI-related code! (if STATUS_COMPLETE or
   *     0 is returned, no errors occurred!)
   */
  protected int processRemoveFile(Context context, Item item, int bitstreamID)
      throws IOException, SQLException, AuthorizeException {
    Bitstream bitstream;

    // Try to find bitstream
    try {
      bitstream = Bitstream.find(context, bitstreamID);
    } catch (NumberFormatException nfe) {
      bitstream = null;
    }

    if (bitstream == null) {
      // Invalid or mangled bitstream ID
      // throw an error and return immediately
      return STATUS_INTEGRITY_ERROR;
    }

    // remove bitstream from bundle..
    // delete bundle if it's now empty
    Bundle[] bundles = bitstream.getBundles();

    bundles[0].removeBitstream(bitstream);

    Bitstream[] bitstreams = bundles[0].getBitstreams();

    // remove bundle if it's now empty
    if (bitstreams.length < 1) {
      item.removeBundle(bundles[0]);
      item.update();
    }

    // no errors occurred
    return STATUS_COMPLETE;
  }
  /*
   If we created a new Bitstream but now realised there is a problem then remove it.
  */
  private void backoutBitstream(SubmissionInfo subInfo, Bitstream b, Item item)
      throws SQLException, AuthorizeException, IOException {
    // remove bitstream from bundle..
    // delete bundle if it's now empty
    Bundle[] bnd = b.getBundles();

    bnd[0].removeBitstream(b);

    Bitstream[] bitstreams = bnd[0].getBitstreams();

    // remove bundle if it's now empty
    if (bitstreams.length < 1) {
      item.removeBundle(bnd[0]);
      item.update();
    }

    subInfo.setBitstream(null);
  }