use of org.dcm4che3.io.DicomOutputStream in project karnak by OsiriX-Foundation.
the class DicomPaneLogic method getWorklistItemInputStreamInDicom.
public InputStream getWorklistItemInputStreamInDicom(Attributes attributes) {
InputStream inputStream = null;
if (attributes != null) {
try (ByteArrayOutputStream tmp = new ByteArrayOutputStream();
DicomOutputStream out = new DicomOutputStream(tmp, UID.ImplicitVRLittleEndian)) {
out.writeDataset(null, attributes);
inputStream = new ByteArrayInputStream(tmp.toByteArray());
} catch (IOException e) {
// $NON-NLS-1$
LOGGER.error("Cannot write dicom file: {}", e.getMessage());
}
}
return inputStream;
}
use of org.dcm4che3.io.DicomOutputStream in project dcm4che by dcm4che.
the class IanSCP method create.
private Attributes create(Association as, Attributes rq, Attributes rqAttrs) throws DicomServiceException {
if (storageDir == null)
return null;
String cuid = rq.getString(Tag.AffectedSOPClassUID);
String iuid = rq.getString(Tag.AffectedSOPInstanceUID);
File file = new File(storageDir, iuid);
if (file.exists())
throw new DicomServiceException(Status.DuplicateSOPinstance).setUID(Tag.AffectedSOPInstanceUID, iuid);
DicomOutputStream out = null;
LOG.info("{}: M-WRITE {}", as, file);
try {
out = new DicomOutputStream(file);
out.writeDataset(Attributes.createFileMetaInformation(iuid, cuid, UID.ExplicitVRLittleEndian), rqAttrs);
} catch (IOException e) {
LOG.warn(as + ": Failed to store Instance Available Notification:", e);
throw new DicomServiceException(Status.ProcessingFailure, e);
} finally {
SafeClose.close(out);
}
return null;
}
use of org.dcm4che3.io.DicomOutputStream in project dcm4che by dcm4che.
the class Jpg2Dcm method convert.
private void convert(Path srcFilePath, Path destFilePath) throws Exception {
ContentType fileType = ContentType.probe(srcFilePath);
Attributes fileMetadata = SAXReader.parse(StreamUtils.openFileOrURL(fileType.getSampleMetadataFile(photo)));
fileMetadata.addAll(staticMetadata);
supplementMissingValue(fileMetadata, Tag.SOPClassUID, fileType.getSOPClassUID(photo));
try (SeekableByteChannel channel = Files.newByteChannel(srcFilePath);
DicomOutputStream dos = new DicomOutputStream(destFilePath.toFile())) {
XPEGParser parser = fileType.newParser(channel);
parser.getAttributes(fileMetadata);
dos.writeDataset(fileMetadata.createFileMetaInformation(parser.getTransferSyntaxUID()), fileMetadata);
dos.writeHeader(Tag.PixelData, VR.OB, -1);
dos.writeHeader(Tag.Item, null, 0);
if (noAPPn && parser.getPositionAfterAPPSegments() > 0) {
copyPixelData(channel, parser.getPositionAfterAPPSegments(), dos, (byte) 0xFF, (byte) JPEG.SOI);
} else {
copyPixelData(channel, parser.getCodeStreamPosition(), dos);
}
dos.writeHeader(Tag.SequenceDelimitationItem, null, 0);
}
System.out.println(MessageFormat.format(rb.getString("converted"), srcFilePath, destFilePath));
}
use of org.dcm4che3.io.DicomOutputStream in project dcm4che by dcm4che.
the class Json2Dcm method writeTo.
public void writeTo(OutputStream out) throws IOException {
if (nofmi)
fmi = null;
else if (fmi == null ? withfmi : tsuid != null && !tsuid.equals(fmi.getString(Tag.TransferSyntaxUID, null))) {
fmi = dataset.createFileMetaInformation(tsuid);
}
@SuppressWarnings("resource") DicomOutputStream dos = new DicomOutputStream(new BufferedOutputStream(out), fmi != null ? UID.ExplicitVRLittleEndian : tsuid != null ? tsuid : UID.ImplicitVRLittleEndian);
dos.setEncodingOptions(encOpts);
dos.writeDataset(fmi, dataset);
dos.finish();
dos.flush();
}
use of org.dcm4che3.io.DicomOutputStream in project dcm4che by dcm4che.
the class StoreSCP method storeTo.
private void storeTo(Association as, Attributes fmi, PDVInputStream data, File file) throws IOException {
LOG.info("{}: M-WRITE {}", as, file);
file.getParentFile().mkdirs();
DicomOutputStream out = new DicomOutputStream(file);
try {
out.writeFileMetaInformation(fmi);
data.copyTo(out);
} finally {
SafeClose.close(out);
}
}
Aggregations