@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);
 }
Esempio n. 2
0
 @Override
 public void write(OutputStream out) throws IOException, WebApplicationException {
   log.info(
       "{}@{} << {}: Content-Type={}, iuid={}",
       new Object[] {
         request.getRemoteUser(),
         request.getRemoteHost(),
         System.identityHashCode(request),
         mediaType,
         fileRef.sopInstanceUID
       });
   DicomInputStream dis = new DicomInputStream(fileRef.getFile());
   dis.setURI(bulkDataURI);
   try {
     dis.setIncludeBulkData(IncludeBulkData.URI);
     Attributes dataset = dis.readDataset(-1, -1);
     dataset.addAll(attrs);
     Object pixelData = dataset.getValue(Tag.PixelAspectRatio);
     if (pixelData instanceof Fragments) {
       Fragments frags = (Fragments) pixelData;
       Object frag0 = frags.get(0);
       BulkData frag1 = (BulkData) frags.get(1);
       dataset.setValue(
           Tag.PixelData,
           VR.OB,
           new BulkData(
               frag1.uri,
               frag1.transferSyntax,
               frag0 == Value.NULL ? frag1.offset - 16 : ((BulkData) frag0).offset - 8,
               -1));
     }
     SAXTransformer.getSAXWriter(new StreamResult(out)).write(dataset);
   } catch (IOException e) {
     throw e;
   } catch (Exception e) {
     throw new WebApplicationException(e);
   } finally {
     SafeClose.close(dis);
   }
 }