code: private byte[] getBytes(DigitalObject object, String pid) throws Exception {
          // These can happily throw exceptions higher
          Payload payload = object.getPayload(pid);
          InputStream in = payload.open();
          byte[] result = null;
  
          // But here, the payload must receive
          // a close before throwing the error
          try {
              result = IOUtils.toByteArray(in);
          } catch (Exception ex) {
              throw ex;
          } finally {
              payload.close();
          }
  
          return result;
      }
docs: Retrieve the payload from storage and return as a byte array.
  
  @param object Our digital object.
  @param pid The payload ID to retrieve.
  @return byte[] The byte array containing payload data
  @throws Exception on any errors