private Foxml11Document createFoxmlObject(String spid, String contentLocation) throws Exception {
    PID pid = PID.getInstance(spid);
    Date date = new Date(1);

    Foxml11Document doc = new Foxml11Document(pid.toString());
    doc.addObjectProperty(Property.STATE, "A");

    if (contentLocation != null && contentLocation.length() > 0) {
      String ds = "DS";
      String dsv = "DS1.0";
      doc.addDatastream(ds, State.A, ControlGroup.M, true);
      doc.addDatastreamVersion(ds, dsv, "text/plain", "label", 1, date);
      doc.setContentLocation(
          dsv, contentLocation, org.fcrepo.server.storage.types.Datastream.DS_LOCATION_TYPE_URL);
    }
    return doc;
  }
 private byte[] getFoxmlObject(String pid, String contentLocation) throws Exception {
   Foxml11Document doc = createFoxmlObject(pid, contentLocation);
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   doc.serialize(out);
   return out.toByteArray();
 }