/*========================================================================= Program: GDCM (Grassroots DICOM). A DICOM library Copyright (c) 2006-2011 Mathieu Malaterre All rights reserved. See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ /** * Simple example showing that Jav UTF-16 string are properly passed to * GDCM layer as locale 8bits * This example also explain the use of try {} finally {} in java to * make sure the C++ RAII design of gdcm.Reader is properly used from * Java and does not leak opened file destructor. * * Compilation: * $ CLASSPATH=gdcm.jar javac ../../gdcm/Examples/Java/ReadFiles.java -d . * * Usage: * $ LD_LIBRARY_PATH=. CLASSPATH=gdcm.jar:. java ReadFiles gdcmData */ import gdcm.*; import java.io.File; public class ReadFiles { static int i = 0; public static void process(String path) { //String path = file.getPath(); assert PosixEmulation.FileExists(path) : "Problem converting to 8bits"; System.out.println("Reading: " + path ); System.out.println("File: " + i++); Reader r = new Reader(); try { r.SetFileName( path ); TagSetType skip = new TagSetType(); skip.insert( new Tag(0x7fe0,0x10) ); boolean b = r.ReadUpToTag( new Tag(0x88,0x200), skip ); //System.out.println("DS:\n" + r.GetFile().GetDataSet().toString() ); } finally { r.delete(); // will properly call C++ destructor and close file descriptor } } // Process only files under dir public static void visitAllFiles(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); for (int i=0; i