@Override
 protected DataWriter createDataWriter(InstanceLocator inst, String tsuid) throws IOException {
   Attributes attrs;
   DicomInputStream in = new DicomInputStream(inst.getFile());
   try {
     if (withoutBulkData) {
       in.setIncludeBulkData(false);
       attrs = in.readDataset(-1, Tag.PixelData);
     } else {
       in.setIncludeBulkDataLocator(true);
       attrs = in.readDataset(-1, -1);
     }
   } finally {
     SafeClose.close(in);
   }
   attrs.addAll((Attributes) inst.getObject());
   adjustPatientID(attrs);
   adjustAccessionNumber(attrs);
   ArchiveApplicationEntity ae = (ArchiveApplicationEntity) as.getApplicationEntity();
   try {
     Templates tpl =
         ae.getAttributeCoercionTemplates(
             inst.cuid, Dimse.C_STORE_RQ, Role.SCU, as.getRemoteAET());
     if (tpl != null) attrs.update(SAXTransformer.transform(attrs, tpl, false, false), null);
   } catch (Exception e) {
     throw new IOException(e);
   }
   return new DataWriterAdapter(attrs);
 }