ensureUID(attrs, Tag.SOPInstanceUID);
Date now = new Date();
attrs.setDate(Tag.InstanceCreationDate, VR.DA, now);
attrs.setDate(Tag.InstanceCreationTime, VR.TM, now);
Attributes fmi = attrs.createFileMetaInformation(transferSyntax);
DicomOutputStream dos = new DicomOutputStream(dcmFile);
try {
dos.writeHeader(Tag.SequenceDelimitationItem, null, 0);
dos.writeHeader(Tag.AcquisitionContextSequence, VR.SQ, -1);
dos.writeHeader(Tag.SequenceDelimitationItem, null, 0);
dos.writeDataset(fmi, attrs);
dos.writeHeader(Tag.PixelData, VR.OB, -1);
if (!cl.hasOption("mpeg")) {
dos.writeHeader(Tag.Item, null, 0);
dos.writeHeader(Tag.Item, null, (jpgLen + 1) & ~1);
dos.write(buffer, 0, jpgHeaderLen);
}
int r;
while ((r = jpgInput.read(buffer)) > 0) {
dos.write(buffer, 0, r);
}
if (!cl.hasOption("mpeg")) {
if ((jpgLen & 1) != 0) {
dos.write(0);
}
}
dos.writeHeader(Tag.SequenceDelimitationItem, null, 0);
} finally {
dos.close();
}
} finally {
jpgInput.close();
}
}