Produced by Araxis Merge on 7/10/2017 1:01:44 PM Central Daylight 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 | C:\AraxisMergeCompare\Pri_un\IV-ehmp_cif\ImagingCommon\main\test\java\gov\va\med\imaging | TestDataGenerator.java | Thu Jun 29 17:22:56 2017 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\IV-ehmp_cif\ImagingCommon\main\test\java\gov\va\med\imaging | TestDataGenerator.java | Thu Jul 6 15:02:46 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 5 | 676 |
| Changed | 4 | 8 |
| 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 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.i maging; | |
| 5 | ||
| 6 | import jav a.io.*; | |
| 7 | import jav a.nio.Byte Buffer; | |
| 8 | import jav a.nio.chan nels.Close dChannelEx ception; | |
| 9 | import jav a.nio.chan nels.Reada bleByteCha nnel; | |
| 10 | import jav a.nio.chan nels.Writa bleByteCha nnel; | |
| 11 | ||
| 12 | import jun it.framewo rk.TestCas e; | |
| 13 | ||
| 14 | /** | |
| 15 | * A test data gener ator class that will build byt e arrays, file and s treams | |
| 16 | * for tes ting. The data will always be ascending values fr om 0 to 25 5, and the n | |
| 17 | * rolling back to 0 . | |
| 18 | * | |
| 19 | * @author
|
|
| 20 | * | |
| 21 | */ | |
| 22 | public cla ss TestDat aGenerator | |
| 23 | { | |
| 24 | pu blic stati c InputStr eam create SlowInputS tream(int length, in t maxBytes OnRead) | |
| 25 | { | |
| 26 | retu rn new Slo wInputStre am(length, maxBytesO nRead); | |
| 27 | } | |
| 28 | ||
| 29 | pu blic stati c Readable ByteChanne l createFa stReadable ByteChanne l(int leng th) | |
| 30 | { | |
| 31 | retu rn new Tes tDataInput Channel(le ngth, Math .min(lengt h, 1024)); | |
| 32 | } | |
| 33 | ||
| 34 | pu blic stati c Readable ByteChanne l createSl owReadable ByteChanne l(int leng th) | |
| 35 | { | |
| 36 | retu rn new Tes tDataInput Channel(le ngth, Math .min(lengt h, 10)); | |
| 37 | } | |
| 38 | ||
| 39 | pu blic stati c byte[] c reateByteA rray(int l ength) | |
| 40 | { | |
| 41 | byte [] retVal = new byte [length]; | |
| 42 | ||
| 43 | for( int index= 0; index < length; + +index) | |
| 44 | retVal [index] = (byte)inde x; | |
| 45 | ||
| 46 | retu rn retVal; | |
| 47 | } | |
| 48 | ||
| 49 | pu blic stati c File cre ateFile(in t length) | |
| 50 | th rows IOExc eption | |
| 51 | { | |
| 52 | File tempDir = getTempDi r(); | |
| 53 | File tempFile = File.cre ateTempFil e("test_", ".data", tempDir); | |
| 54 | ||
| 55 | File OutputStre am outStre am = new F ileOutputS tream(temp File); | |
| 56 | ||
| 57 | for( int index= 0; index<l ength; ++i ndex) | |
| 58 | outStr eam.write( (byte)inde x); | |
| 59 | ||
| 60 | outS tream.clos e(); | |
| 61 | ||
| 62 | retu rn tempFil e; | |
| 63 | } | |
| 64 | ||
| 65 | pu blic stati c File cre ateBlankDe stinationF ile() | |
| 66 | th rows IOExc eption | |
| 67 | { | |
| 68 | File tempDir = getTempDi r(); | |
| 69 | File tempFile = File.cre ateTempFil e("test_", ".data", tempDir); | |
| 70 | ||
| 71 | retu rn tempFil e; | |
| 72 | } | |
| 73 | ||
| 74 | /* * | |
| 75 | * Create a writabe by te channel that will check tha t the valu es being w ritten | |
| 76 | * follow th e test dat a generato r pattern. | |
| 77 | * | |
| 78 | * @return | |
| 79 | * / | |
| 80 | pu blic stati c Writable ByteChanne l createTe stDataVali datingWrit ableByteCh annel() | |
| 81 | { | |
| 82 | retu rn new Val idatingWri tableByteC hannel(); | |
| 83 | } | |
| 84 | ||
| 85 | /* * | |
| 86 | * Validates for the t est data p attern and writes no more than 10 bytes per call t o | |
| 87 | * write(). This is u seful for testing no n-blocking channels. | |
| 88 | * | |
| 89 | * @return | |
| 90 | * / | |
| 91 | pu blic stati c Writable ByteChanne l createTe stDataVali datingSlow WritableBy teChannel( ) | |
| 92 | { | |
| 93 | retu rn new Val idatingWri tableByteC hannel(10) ; | |
| 94 | } | |
| 95 | ||
| 96 | /* * | |
| 97 | * @return | |
| 98 | * / | |
| 99 | pr ivate stat ic File te mpDir = nu ll; | |
| 100 | ||
| 101 | pr ivate stat ic synchro nized File getTempDi r() | |
| 102 | { | |
| 103 | if(t empDir != null) | |
| 104 | return tempDir; | |
| 105 | ||
| 106 | Stri ng tempDir Name = Sys tem.getenv ("TEMP");; | |
| 107 | if(t empDirName == null) | |
| 108 | tempDi rName = "/ temp"; | |
| 109 | ||
| 110 | temp Dir = new File(tempD irName); | |
| 111 | if(! tempDir.e xists()) | |
| 112 | tempDi r.mkdirs() ; | |
| 113 | ||
| 114 | retu rn tempDir ; | |
| 115 | } | |
| 116 | ||
| 117 | /* * | |
| 118 | * A method that simpl y validate s that a b yte array has | |
| 119 | * valid tes t data as defined by this clas s (ascendi ng values from 0 to 255). | |
| 120 | * | |
| 121 | * @param so urce | |
| 122 | * @return | |
| 123 | * / | |
| 124 | pu blic stati c void ass ertValidTe stData(byt e[] source ) | |
| 125 | { | |
| 126 | for( int index= 0; index<s ource.leng th; ++inde x) | |
| 127 | TestCa se.assertE quals( "Va lue at " + index + " is not as expected." , (byte)in dex, sourc e[index] ) ; | |
| 128 | } | |
| 129 | ||
| 130 | pu blic stati c void ass ertValidTe stData(Fil e file) | |
| 131 | th rows IOExc eption | |
| 132 | { | |
| 133 | asse rtValidTes tData(new FileInputS tream(file )); | |
| 134 | } | |
| 135 | ||
| 136 | pu blic stati c void ass ertValidTe stData(Inp utStream i nStream) | |
| 137 | th rows IOExc eption | |
| 138 | { | |
| 139 | int index = 0; | |
| 140 | for( int value = inStream .read(); v alue >= 0; value = i nStream.re ad()) | |
| 141 | { | |
| 142 | TestCa se.assertE quals( "Va lue at " + index + " is not as expected." , (byte)in dex, (byte )value ); | |
| 143 | ||
| 144 | index+ +; | |
| 145 | } | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * @author
|
|
| 151 | * | |
| 152 | * A test class that generates test data (ascendin g values f rom 0 to 2 55) and pr ovides | |
| 153 | * only a limited nu mber of by tes per re ad. | |
| 154 | * This is to simula te a netwo rk connect ion where the number of bytes available will | |
| 155 | * usually be less t han the bu ffer sizes passed to the read. | |
| 156 | * | |
| 157 | */ | |
| 158 | class Slow InputStrea m | |
| 159 | extends In putStream | |
| 160 | { | |
| 161 | pr ivate int maxBytesOn Read = 10; | |
| 162 | ||
| 163 | pr ivate int length; | |
| 164 | pu blic SlowI nputStream (int lengt h, int max BytesOnRea d) | |
| 165 | { | |
| 166 | this .length = length; | |
| 167 | this .maxBytesO nRead = ma xBytesOnRe ad; | |
| 168 | } | |
| 169 | ||
| 170 | pr ivate int index; | |
| 171 | pr ivate byte getNextBy te() | |
| 172 | { | |
| 173 | if(i ndex >= th is.length) | |
| 174 | return -1; | |
| 175 | retu rn (byte)i ndex++; | |
| 176 | } | |
| 177 | ||
| 178 | /* (non-Java doc) | |
| 179 | * @see java .io.InputS tream#read () | |
| 180 | * / | |
| 181 | @O verride | |
| 182 | pu blic int r ead() | |
| 183 | th rows IOExc eption | |
| 184 | { | |
| 185 | retu rn getNext Byte(); | |
| 186 | } | |
| 187 | ||
| 188 | @O verride | |
| 189 | pu blic int a vailable() | |
| 190 | th rows IOExc eption | |
| 191 | { | |
| 192 | retu rn maxByte sOnRead; | |
| 193 | } | |
| 194 | ||
| 195 | @O verride | |
| 196 | pu blic int r ead(byte[] b) throws IOExcepti on | |
| 197 | { | |
| 198 | retu rn this.re ad(b, 0, b .length); | |
| 199 | } | |
| 200 | ||
| 201 | pr ivate bool ean eofRea ched = fal se; | |
| 202 | @O verride | |
| 203 | pu blic int r ead(byte[] b, int of f, int len ) throws I OException | |
| 204 | { | |
| 205 | if(e ofReached) | |
| 206 | return -1; | |
| 207 | ||
| 208 | len = Math.min (b.length - off, len ); // do not overru n the buff er | |
| 209 | int maxBytesTo Return = M ath.min(le n, maxByte sOnRead); | |
| 210 | ||
| 211 | int bytesRead = 0; | |
| 212 | for( int index= off; index < off+max BytesToRet urn && !eo fReached; ++index) | |
| 213 | { | |
| 214 | b[inde x] = getNe xtByte(); | |
| 215 | bytesR ead++; | |
| 216 | eofRea ched = (b[ index] < 0 ); | |
| 217 | } | |
| 218 | ||
| 219 | retu rn bytesRe ad; | |
| 220 | } | |
| 221 | } | |
| 222 | ||
| 223 | /** | |
| 224 | * A trivi al Readabl eByteChann el impleme ntation th at provide s very few | |
| 225 | * bytes p er read. | |
| 226 | * | |
| 227 | * @author
|
|
| 228 | * | |
| 229 | */ | |
| 230 | class Test DataInputC hannel | |
| 231 | implements ReadableB yteChannel | |
| 232 | { | |
| 233 | pr ivate int maxBytesOn Read = 10; | |
| 234 | pr ivate int length; | |
| 235 | pr ivate int totalBytes Read; | |
| 236 | pr ivate bool ean open = true; | |
| 237 | pr ivate bool ean eofRea ched = fal se; | |
| 238 | ||
| 239 | pu blic TestD ataInputCh annel(int maxBytesOn Read, int length) | |
| 240 | { | |
| 241 | this .totalByte sRead = 0; | |
| 242 | this .maxBytesO nRead = ma xBytesOnRe ad; | |
| 243 | this .length = length; | |
| 244 | } | |
| 245 | ||
| 246 | pr ivate int index; | |
| 247 | pr ivate byte getNextBy te() | |
| 248 | { | |
| 249 | if(i ndex >= th is.length) | |
| 250 | return -1; | |
| 251 | retu rn (byte)i ndex++; | |
| 252 | } | |
| 253 | ||
| 254 | pu blic int r ead(ByteBu ffer dst) | |
| 255 | th rows IOExc eption | |
| 256 | { | |
| 257 | if(e ofReached) | |
| 258 | return -1; | |
| 259 | ||
| 260 | int bytesRead = 0; | |
| 261 | for( int index= 0; | |
| 262 | index < maxBytes OnRead && !eofReache d && dst.p osition() < dst.limi t(); | |
| 263 | ++inde x) | |
| 264 | { | |
| 265 | dst.pu t(getNextB yte()); | |
| 266 | ++byte sRead; | |
| 267 | ++tota lBytesRead ; | |
| 268 | eofRea ched = (to talBytesRe ad >= leng th); | |
| 269 | } | |
| 270 | ||
| 271 | retu rn bytesRe ad; | |
| 272 | } | |
| 273 | ||
| 274 | pu blic void close() | |
| 275 | th rows IOExc eption | |
| 276 | { | |
| 277 | open = false; | |
| 278 | } | |
| 279 | ||
| 280 | pu blic boole an isOpen( ) | |
| 281 | { | |
| 282 | retu rn open; | |
| 283 | } | |
| 284 | } | |
| 285 | ||
| 286 | /** | |
| 287 | * @author
|
|
| 288 | * | |
| 289 | * A writa ble byte c hannel tha t validate s the data as it is being writ ten to. | |
| 290 | * | |
| 291 | * If byte sPerWrite is specifi ed then th is class d oes not wr ite all of the avail able bytes | |
| 292 | * on the every call to write. | |
| 293 | * | |
| 294 | */ | |
| 295 | class Vali datingWrit ableByteCh annel | |
| 296 | implements WritableB yteChannel | |
| 297 | { | |
| 298 | pr ivate int channelInd ex = 0; | |
| 299 | pr ivate bool ean open = true; | |
| 300 | pr ivate int bytesPerWr ite = Inte ger.MAX_VA LUE; | |
| 301 | ||
| 302 | Va lidatingWr itableByte Channel() | |
| 303 | { | |
| 304 | ||
| 305 | } | |
| 306 | Va lidatingWr itableByte Channel(in t bytesPer Write) | |
| 307 | { | |
| 308 | ||
| 309 | } | |
| 310 | ||
| 311 | pu blic int w rite(ByteB uffer src) | |
| 312 | th rows IOExc eption | |
| 313 | { | |
| 314 | if(! isOpen()) | |
| 315 | throw new Closed ChannelExc eption(); | |
| 316 | ||
| 317 | int bytesWritt en = 0; | |
| 318 | whil e(src.rema ining() > 0 && bytes Written <= bytesPerW rite) | |
| 319 | { | |
| 320 | byte v alue = src .get(); | |
| 321 | if( va lue != (by te)channel Index) | |
| 322 | throw ne w StreamCo rruptedExc eption( | |
| 323 | "Test data at positi on " + cha nnelIndex + " is not correct, expected = " + (byte )channelIn dex + ", a ctual was " + value | |
| 324 | ); | |
| 325 | ||
| 326 | channe lIndex++; | |
| 327 | ++byte sWritten; | |
| 328 | } | |
| 329 | ||
| 330 | retu rn bytesWr itten; | |
| 331 | } | |
| 332 | ||
| 333 | pu blic void close() th rows IOExc eption | |
| 334 | { | |
| 335 | open = false; | |
| 336 | } | |
| 337 | ||
| 338 | pu blic boole an isOpen( ) | |
| 339 | { | |
| 340 | retu rn open; | |
| 341 | } | |
| 342 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.