private List<Attributes> loadAttributesList(Path path, int[]tags) throws Exception { List<Attributes> list = new ArrayList<>(); DicomInputStream din = null; try { List<File> files = (List<File>) FileUtils.listFiles(path.toFile(), TrueFileFilter.TRUE, TrueFileFilter.TRUE); for (File file : files) { din = new DicomInputStream(file); Attributes dataSet = din.readDataset(-1, -1); list.add(new Attributes(dataSet, tags)); din.close(); } return list; } finally { if (din != null) din.close(); } } /**
private void loadDcmDocuments() throws Exception { Path testPath = xdsi.resolve(testPfn); Utility.isValidPfn("test doc", testPath, PfnType.FILE, "r"); din = new DicomInputStream(testPath.toFile()); testAttr = din.readDataset(-1, Tag.PixelData); din.close(); din = null; Path stdPath = xdsi.resolve(stdPfn); Utility.isValidPfn("std doc", stdPath, PfnType.FILE, "r"); din = new DicomInputStream(stdPath.toFile()); stdAttr = din.readDataset(-1, Tag.PixelData); din.close(); din = null; }
private List<AttributesAndHash> loadAttributesList(List<String> pfns, int[]tags, boolean checkHash, boolean checkAttr) throws Exception { List<AttributesAndHash> list = new ArrayList<>(); DicomInputStream din = null; try { for (String pfn : pfns) { AttributesAndHash attributesAndHash = new AttributesAndHash(); if (checkAttr) { din = new DicomInputStream(new File(pfn)); Attributes dataSet = din.readDataset(-1, -1); attributesAndHash.attributes = new Attributes(dataSet, tags); } if (checkHash) attributesAndHash.hash = getMd5ForFile(new File(pfn)); list.add(attributesAndHash); } return list; } catch (Exception e) { String em = e.getMessage(); return list; } finally { if (din != null) din.close(); } }
BufferedImage jpg = ImageIO.read(new File("myjpg.jpg")); //Convert the image to a byte array DataBufferUShort buff = (DataBufferUShort) jpg.getData().getDataBuffer(); short[] data = buff.getData(); ByteBuffer byteBuf = ByteBuffer.allocate(2*data.length); int i = 0; while (data.length > i) { byteBuf.putShort(data[i]); i++; } //Copy a header DicomInputStream dis = new DicomInputStream(new File("fileToCopyheaderFrom.dcm")); Attributes meta = dis.readFileMetaInformation(); Attributes attribs = dis.readDataset(-1, Tag.PixelData); dis.close(); //Change the rows and columns attribs.setInt(Tag.Rows, VR.US, jpg.getHeight()); attribs.setInt(Tag.Columns, VR.US, jpg.getWidth()); System.out.println(byteBuf.array().length); //Attributes attribs = new Attributes(); //Write the file attribs.setBytes(Tag.PixelData, VR.OW, byteBuf.array()); DicomOutputStream dcmo = new DicomOutputStream(new File("myDicom.dcm")); dcmo.writeFileMetaInformation(meta); attribs.writeTo(dcmo); dcmo.close();
@SuppressWarnings("unchecked") public static void main(String[] args) { try { CommandLine cl = parseComandLine(args); Dcm2Json main = new Dcm2Json(); main.setIndent(cl.hasOption("I")); configureBulkdata(main, cl); String fname = fname(cl.getArgList()); if (fname.equals("-")) { main.parse(new DicomInputStream(System.in)); } else { DicomInputStream dis = new DicomInputStream(new File(fname)); try { main.parse(dis); } finally { dis.close(); } } } catch (ParseException e) { System.err.println("dcm2xml: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("dcm2xml: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
main.parse(dis); } finally { dis.close();
@SuppressWarnings("unchecked") public static void main(String[] args) { try { CommandLine cl = parseComandLine(args); Dcm2Json main = new Dcm2Json(); main.setIndent(cl.hasOption("I")); configureBulkdata(main, cl); String fname = fname(cl.getArgList()); if (fname.equals("-")) { main.parse(new DicomInputStream(System.in)); } else { DicomInputStream dis = new DicomInputStream(new File(fname)); try { main.parse(dis); } finally { dis.close(); } } } catch (ParseException e) { System.err.println("dcm2xml: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("dcm2xml: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
main.parse(dis); } finally { dis.close();
public Attributes parseAttributesWithLazyBulkData(Association as, File file) throws IOException { DicomInputStream in = null; try { in = new DicomInputStream(file); in.setIncludeBulkData(IncludeBulkData.URI); return in.readDataset(-1, -1); } catch (IOException e) { LOG.warn(as + ": Failed to decode dataset:", e); throw new DicomServiceException(Status.CannotUnderstand); } finally { in.close(); } }
main.parse(dis); } finally { dis.close();
main.parse(dis); } finally { dis.close();
main.parse(dis); } finally { dis.close();
main.parse(dis); } finally { dis.close();
} finally { if (din != null) try { din.close(); } catch (Exception ignore) {}
main.parse(dis); } finally { dis.close();
} finally { if (din != null) try { din.close(); } catch (Exception ignore) {}
private void prsSameKOSDcm(AssertionEngine engine, Assertion a, OMElement assertion_output) throws XdsInternalException { try { // pfn of std KON.dcm String pfn = a.xpath.trim(); String stdDcmPfn = Paths.get(testConfig.testplanDir.getAbsolutePath(), pfn).toString(); SimulatorTransaction simulatorTransaction = getSimulatorTransaction(a); simulatorTransaction.setStdPfn(stdDcmPfn); // load sop instance uid from test kos for later comparison String tstKOSPfn = simulatorTransaction.getPfns().get(0); DicomInputStream din = new DicomInputStream(new File(tstKOSPfn)); Attributes at = din.readDataset(-1, Tag.PixelData); String siu = at.getString(Tag.SOPInstanceUID); reportManager.addReport(new ReportDTO("SOPInstanceUID", siu)); din.close(); TestRAD68 testInstance = new TestRAD68(); testInstance.initializeTest(a.process, simulatorTransaction); testInstance.runTest(); Results results = testInstance.getResults(a.process); String rep = results.toString(); CAT cat = CAT.SUCCESS; if (results.getErrorCount() > 0) cat = CAT.ERROR; store(engine, cat, rep); reportManagerPostRun(); } catch (Exception e) { e.printStackTrace(); throw new XdsInternalException("ImgDetailTransaction - sameKOSDcm: " + e.getMessage()); } }
dataset = dis.readDataset(-1, -1); } finally { dis.close();
dataset = dis.readDataset(-1, -1); } finally { dis.close();