Produced by Araxis Merge on 12/5/2017 12:06:39 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\DicomServiceProvider\main\src\java\gov\va\med\imaging\dicom\parser\io | DataElementReader.java | Mon Dec 4 21:35:22 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\DicomServiceProvider\main\src\java\gov\va\med\imaging\dicom\parser\io | DataElementReader.java | Mon Dec 4 21:59:35 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 484 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.med.i maging.dic om.parser. io; | |
| 2 | ||
| 3 | import gov .va.med.im aging.dico m.dataset. ValueRepre sentation; | |
| 4 | import gov .va.med.im aging.dico m.dataset. elements.D ataElement ; | |
| 5 | import gov .va.med.im aging.dico m.dataset. elements.D ataElement Tag; | |
| 6 | import gov .va.med.im aging.dico m.exceptio ns.DicomFo rmatExcept ion; | |
| 7 | import gov .va.med.im aging.dico m.exceptio ns.DicomFo rmatPixelD ataExcepti on; | |
| 8 | import gov .va.med.im aging.dico m.exceptio ns.Incompa tibleValue LengthFiel d; | |
| 9 | import gov .va.med.im aging.dico m.exceptio ns.Invalid VRExceptio n; | |
| 10 | import gov .va.med.im aging.dico m.exceptio ns.Invalid VRModeExce ption; | |
| 11 | import gov .va.med.im aging.dico m.parser.i mpl.DataEl ementFacto ry; | |
| 12 | ||
| 13 | import jav a.io.IOExc eption; | |
| 14 | ||
| 15 | import org .apache.lo gging.log4 j.Level; | |
| 16 | import org .apache.lo gging.log4 j.LogManag er; | |
| 17 | import org .apache.lo gging.log4 j.Logger; | |
| 18 | ||
| 19 | /** | |
| 20 | * This cl ass reads from the g iven strea m, returni ng a DataE lement for | |
| 21 | * each ca ll to getN extDataEle ment() | |
| 22 | * | |
| 23 | * @author
|
|
| 24 | * | |
| 25 | */ | |
| 26 | public cla ss DataEle mentReader | |
| 27 | { | |
| 28 | pr ivate fina l DataElem entLimited InputStrea m inputStr eam; | |
| 29 | pr ivate fina l DataElem entFactory dataEleme ntFactory; | |
| 30 | pr ivate Logg er logger = LogManag er.getLogg er(this.ge tClass().g etName()); | |
| 31 | ||
| 32 | ||
| 33 | /* * | |
| 34 | * A package level con structor t o be used to creater readers o f child da ta sets. | |
| 35 | * | |
| 36 | * @param in putStream | |
| 37 | * @param da taElementF actory | |
| 38 | * / | |
| 39 | pu blic DataE lementRead er(DataEle mentLimite dInputStre am inputSt ream, Data ElementFac tory dataE lementFact ory) | |
| 40 | { | |
| 41 | if(i nputStream == null | | dataElem entFactory == null) | |
| 42 | throw new Illega lArgumentE xception( | |
| 43 | "Input Str eam is " + (inputStr eam == nul l ? "NULL" : "not nu ll") + | |
| 44 | ", Data El ement Fact ory is " + (dataElem entFactory == null ? "NULL," : "not null .") ); | |
| 45 | this .inputStre am = input Stream; | |
| 46 | this .dataEleme ntFactory = dataElem entFactory ; | |
| 47 | } | |
| 48 | ||
| 49 | /* * | |
| 50 | * @re turn the i nputStream | |
| 51 | */ | |
| 52 | public DataEleme ntLimitedI nputStream getInputS tream() | |
| 53 | { | |
| 54 | re turn input Stream; | |
| 55 | } | |
| 56 | ||
| 57 | /* * | |
| 58 | * @re turn the e lementFact ory | |
| 59 | */ | |
| 60 | public DataEleme ntFactory getDataEle mentFactor y() | |
| 61 | { | |
| 62 | re turn dataE lementFact ory; | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * | |
| 67 | * @re turn | |
| 68 | * @th rows IOExc eption | |
| 69 | * @th rows Inval idVRModeEx ception | |
| 70 | * @th rows Inval idVRExcept ion | |
| 71 | * @th rows Incom patibleVal ueLengthFi eld | |
| 72 | */ | |
| 73 | pu blic DataE lement<?> readNextDa taElement( ) | |
| 74 | th rows | |
| 75 | IOEx ception, I nvalidVRMo deExceptio n, Invalid VRExceptio n, Incompa tibleValue LengthFiel d, | |
| 76 | Dico mFormatExc eption | |
| 77 | { | |
| 78 | Valu eRepresent ation vr = null; | |
| 79 | long valueLeng th = 0; // a 16 or 3 2 bit unsi gned, stor ed as long | |
| 80 | byte [] value = null; | |
| 81 | Data ElementTag dataEleme ntTag = in putStream. readNextDa taElementT ag(); | |
| 82 | ||
| 83 | bool ean readin gPixelData = DataEle mentTag.PI XEL_DATA_T AG.equals( dataElemen tTag); | |
| 84 | ||
| 85 | logg er.trace( | |
| 86 | "Readi ng element tag '" + (dataEleme ntTag == n ull ? "NUL L, (EOF)" : dataElem entTag.toS tring()) + "'." ); | |
| 87 | if(d ataElement Tag == nul l) // N ULL indica tes the en d of file | |
| 88 | return null; | |
| 89 | ||
| 90 | // I f we are i n explicit VR mode t hen the ne xt piece o f data MUS T be a VR. | |
| 91 | // E XCEPT (fro m the spec ification Section 5 Page 40): | |
| 92 | // T here are t hree speci al SQ rela ted Data E lements th at are not ruled by the VR | |
| 93 | // e ncoding ru les convey ed by the Transfer S yntax. The y shall be encoded a s Implicit VR. | |
| 94 | // T hese speci al Data El ements are Item (FFF E,E000), I tem Delimi tation Ite m (FFFE,E0 0D), | |
| 95 | // a nd Sequenc e Delimita tion Item (FFFE,E0DD ). However , the Data Set withi n the Valu e Field | |
| 96 | // o f the Data Element I tem (FFFE, E000) shal l be encod ed accordi ng to the rules conv eyed by | |
| 97 | // t he Transfe r Syntax. | |
| 98 | // T he special sequence elements a lways have no VR and always ha ve a 4 byt e length i mmediately | |
| 99 | // f ollowing. | |
| 100 | if( dataElemen tTag.equal s(DataElem entTag.SEQ UENCE_DELI MITATION_T AG) || | |
| 101 | dataEl ementTag.e quals(Data ElementTag .ITEM_DELI MITATION_T AG) || | |
| 102 | dataEl ementTag.e quals(Data ElementTag .SEQUENCE_ ITEM_TAG) ) | |
| 103 | { | |
| 104 | logger .log(Level .TRACE, "S equence de limitation element " + dataEle mentTag.to String()); | |
| 105 | valueL ength = in putStream. readFourBy tesIntoLon g(); // should be 0x0000000 0 for SEQU ENCE_DELIM ITATION_TA G and ITEM _DELIMITAT ION_TAG | |
| 106 | } | |
| 107 | ||
| 108 | else if( getDa taElementF actory().i sExplicitV R() ) | |
| 109 | { | |
| 110 | vr = i nputStream .readValue Representa tion(); | |
| 111 | logger .log(Level .TRACE, "E xplicit VR - " + vr. toString() ); | |
| 112 | ||
| 113 | // For VRs of OB , OW, OF, SQ, UN and UT the 16 bits foll owing the two charac ter VR Fie ld | |
| 114 | // the Value Len gth Field is a 32-bi t unsigned integer. | |
| 115 | // If the Value Field has an Explici t Length, then the V alue Lengt h Field sh all contai n a value | |
| 116 | // equ al to the length (in bytes) of the Value Field. Ot herwise, t he Value F ield has a n | |
| 117 | // Und efined Len gth and a Sequence D elimitatio n Item mar ks the end of the Va lue Field. | |
| 118 | if( vr == ValueR epresentat ion.OB || vr == Valu eRepresent ation.OW | | vr == Va lueReprese ntation.OF || | |
| 119 | vr == Va lueReprese ntation.SQ || vr == ValueRepre sentation. UN || vr = = ValueRep resentatio n.UT ) | |
| 120 | { | |
| 121 | logger.l og(Level.T RACE, "Exp licit VR, discarding two bytes between V R and leng th."); | |
| 122 | inputS tream.skip (2); | |
| 123 | logger.l og(Level.T RACE, "Exp licit VR, reading 4 byte lengt h."); | |
| 124 | valueL ength = in putStream. readFourBy tesIntoLon g(); | |
| 125 | ||
| 126 | // Not e: VRs of UT may not have an U ndefined L ength, ie. a Value L ength of F FFFFFFFH. | |
| 127 | if(vr == ValueRe presentati on.UT && v alueLength == DataEl ement.INDE TERMINATE_ LENGTH) | |
| 128 | throw ne w Incompat ibleValueL engthField (vr, value Length); | |
| 129 | } | |
| 130 | else | |
| 131 | { | |
| 132 | int valu eLengthLen gth = vr.g etExpected DataLength FieldLengt h(); | |
| 133 | logger.l og(Level.T RACE, "Exp licit VR, reading va lue length field, " + valueLen gthLength + " bytes. "); | |
| 134 | valueLen gth = valu eLengthLen gth == 2 ? | |
| 135 | inputStrea m.readTwoB ytesIntoLo ng() : | |
| 136 | inputStrea m.readFour BytesIntoL ong(); | |
| 137 | } | |
| 138 | } | |
| 139 | ||
| 140 | // W hen using the Implic it VR stru cture. | |
| 141 | // I f the Valu e Field ha s an Expli cit Length then the Value Leng th Field s hall conta in a value | |
| 142 | // e qual to th e length ( in bytes) of the Val ue Field. Otherwise, the Value Field has an Undefi ned | |
| 143 | // L ength and a Sequence Delimitat ion Item m arks the e nd of the Value Fiel d. | |
| 144 | else | |
| 145 | { | |
| 146 | logger .log(Level .TRACE, "I mplicit VR , reading 4 byte len gth."); | |
| 147 | valueL ength = in putStream. readFourBy tesIntoLon g(); | |
| 148 | } | |
| 149 | ||
| 150 | // a t this poi nt the dat a element value repr esentation is known, either ex plicitly s tated | |
| 151 | // o r implicit ly determi ned | |
| 152 | Valu eRepresent ation data ElementVR = | |
| 153 | vr == null ? | |
| 154 | getDat aElementFa ctory().ge tImplicitV R(dataElem entTag) : | |
| 155 | vr; | |
| 156 | ||
| 157 | logg er.trace( | |
| 158 | "eleme nt tag " + dataEleme ntTag.toSt ring() + " , " + | |
| 159 | (vr == null ? "i mplicit-" : "explici t-") + "-" + dataEle mentVR + " " + | |
| 160 | valueL ength + " bytes."); | |
| 161 | ||
| 162 | // i f the data element i s a sequen ce (either explicitl y stated o r implicit ly determi ned) | |
| 163 | if( dataElemen tVR == Val ueRepresen tation.SQ ) | |
| 164 | { | |
| 165 | if( va lueLength == DataEle ment.INDET ERMINATE_L ENGTH) | |
| 166 | { | |
| 167 | value = inputStrea m.readUnti lElementTa g(DataElem entTag.ITE M_DELIMITA TION_TAG, DataElemen tTag.SEQUE NCE_DELIMI TATION_TAG ); | |
| 168 | } | |
| 169 | else i f( valueLe ngth == 0) | |
| 170 | { | |
| 171 | value = null; | |
| 172 | } | |
| 173 | else | |
| 174 | { | |
| 175 | // alway s read an even numbe r of bytes | |
| 176 | value = new byte[( int)valueL ength + (( int)valueL ength % 2) ]; // saf ely downca st because its an un signed num ber | |
| 177 | inputStr eam.readFu lly(value) ; // read th e entire t ag element | |
| 178 | } | |
| 179 | ||
| 180 | return getDataEl ementFacto ry().isExp licitVR() ? | |
| 181 | getDataEle mentFactor y().create DataElemen t(dataElem entTag, vr , valueLen gth, value ) : | |
| 182 | getDataEle mentFactor y().create DataElemen t(dataElem entTag, nu ll, valueL ength, val ue); | |
| 183 | } | |
| 184 | // S ee PS 3.5- 2007 Page 67 for how OB, OW, a nd OF are interprete d | |
| 185 | // I n addition to SQ, th e followin g VRs may also have an indeter minate len gth. | |
| 186 | // V alueRepres entation.O B, ValueRe presentati on.OW, Val ueRepresen tation.OF, | |
| 187 | // V alueRepres entation.U N, ValueRe presentati on.UT | |
| 188 | // A valueLeng th of 0xFF FFFFFF mea ns an inde terminate length, re ad until t he delimit er element | |
| 189 | if( readingPix elData ) | |
| 190 | { | |
| 191 | if( da taElementV R == Value Representa tion.OB || | |
| 192 | dataElem entVR == V alueRepres entation.O W || | |
| 193 | dataElem entVR == V alueRepres entation.O F ) | |
| 194 | { | |
| 195 | if( valu eLength == DataEleme nt.INDETER MINATE_LEN GTH) | |
| 196 | { | |
| 197 | value = in putStream. readUntilE lementTag( DataElemen tTag.ITEM_ DELIMITATI ON_TAG, Da taElementT ag.SEQUENC E_DELIMITA TION_TAG); | |
| 198 | } | |
| 199 | else if( valueLeng th == 0) | |
| 200 | { | |
| 201 | value = nu ll; | |
| 202 | } | |
| 203 | else | |
| 204 | { | |
| 205 | // always read an ev en number of bytes | |
| 206 | value = ne w byte[(in t)valueLen gth + ((in t)valueLen gth % 2)]; // safel y downcast because i ts an unsi gned numbe r | |
| 207 | inputStrea m.readFull y(value); // read the entire tag element | |
| 208 | } | |
| 209 | ||
| 210 | return g etDataElem entFactory ().createD ataElement ( | |
| 211 | da taElementT ag, | |
| 212 | (g etDataElem entFactory ().isExpli citVR() ? vr : null) , | |
| 213 | va lueLength, | |
| 214 | va lue); | |
| 215 | } | |
| 216 | else | |
| 217 | { | |
| 218 | throw ne w DicomFor matPixelDa taExceptio n("The pix el data wa s found in a '" + da taElementV R + " valu e represen tation."); | |
| 219 | } | |
| 220 | } | |
| 221 | else | |
| 222 | { | |
| 223 | // sho uld only b e ValueRep resentatio n.UN and V alueRepres entation.U T | |
| 224 | if( va lueLength == DataEle ment.INDET ERMINATE_L ENGTH) | |
| 225 | { | |
| 226 | value = inputStrea m.readUnti lElementTa g(DataElem entTag.ITE M_DELIMITA TION_TAG); | |
| 227 | } | |
| 228 | else i f( valueLe ngth == 0) | |
| 229 | { | |
| 230 | value = null; | |
| 231 | } | |
| 232 | else | |
| 233 | { | |
| 234 | value = new byte[( int)valueL ength]; // safely downcast b ecause its an unsign ed number | |
| 235 | inputStr eam.readFu lly(value) ; // read th e entire t ag element | |
| 236 | } | |
| 237 | ||
| 238 | return getDataEl ementFacto ry().isExp licitVR() ? | |
| 239 | getDataE lementFact ory().crea teDataElem ent(dataEl ementTag, vr, valueL ength, val ue) : | |
| 240 | getDataE lementFact ory().crea teDataElem ent(dataEl ementTag, null, valu eLength, v alue); | |
| 241 | } | |
| 242 | } | |
| 243 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.