Produced by Araxis Merge on 6/18/2018 3:36:59 PM Eastern 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 | CTT_DM2_v7.zip\CTT_ISAAC\hl7-messaging\src\main\java\gov\vha\issac\ochre\services\utility | ChecksumCalculator.java | Tue Jun 12 16:42:14 2018 UTC |
| 2 | CTT_DM2_v7.zip\CTT_ISAAC\hl7-messaging\src\main\java\gov\vha\issac\ochre\services\utility | ChecksumCalculator.java | Thu Jun 14 16:20:31 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 446 |
| 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 | /** | |
| 2 | * Copyrig ht Notice | |
| 3 | * | |
| 4 | * This is a work of the U.S. Government and is no t subject to copyrig ht | |
| 5 | * protect ion in the United St ates. Fore ign copyri ghts may a pply. | |
| 6 | * | |
| 7 | * License d under th e Apache L icense, Ve rsion 2.0 (the "Lice nse"); | |
| 8 | * you may not use t his file e xcept in c ompliance with the L icense. | |
| 9 | * You may obtain a copy of th e License at | |
| 10 | * | |
| 11 | * http:// www.apache .org/licen ses/LICENS E-2.0 | |
| 12 | * | |
| 13 | * Unless required b y applicab le law or agreed to in writing , software | |
| 14 | * distrib uted under the Licen se is dist ributed on an "AS IS " BASIS, | |
| 15 | * WITHOUT WARRANTIE S OR CONDI TIONS OF A NY KIND, e ither expr ess or imp lied. | |
| 16 | * See the License f or the spe cific lang uage gover ning permi ssions and | |
| 17 | * limitat ions under the Licen se. | |
| 18 | */ | |
| 19 | package go v.vha.issa c.ochre.se rvices.uti lity; | |
| 20 | ||
| 21 | import jav a.io.Buffe redWriter; | |
| 22 | import jav a.io.File; | |
| 23 | import jav a.io.FileW riter; | |
| 24 | import jav a.io.IOExc eption; | |
| 25 | import jav a.security .MessageDi gest; | |
| 26 | import jav a.security .NoSuchAlg orithmExce ption; | |
| 27 | ||
| 28 | import gov .vha.isaac .ochre.ser vices.exce ption.STSE xception; | |
| 29 | ||
| 30 | /** | |
| 31 | * This cl ass is por ted from t he legacy VETS appli cation. It calculate s the chec ksum on a string and | |
| 32 | * writes the string to a file for loggi ng. | |
| 33 | * | |
| 34 | * @author PII | |
| 35 | * | |
| 36 | */ | |
| 37 | public cla ss Checksu mCalculato r | |
| 38 | { | |
| 39 | // NOTE: chec ksum is ca lculated b efore writ ing to the file. Fi le is for logging. | |
| 40 | ||
| 41 | pr ivate stat ic final i nt MAX_FIL E_NAME_LEN GTH = 100; | |
| 42 | pr ivate stat ic final S tring FILE _APPEND_NA ME = "_log "; | |
| 43 | pr ivate stat ic final S tring FILE _EXTENSION = ".csm"; | |
| 44 | pr ivate stat ic final S tring CHEC KSUM_DIR = "checksum "; | |
| 45 | pr ivate Buff eredWriter bufferWri ter; | |
| 46 | pr ivate Mess ageDigest appmd5; | |
| 47 | ||
| 48 | /* * | |
| 49 | * Construct or to crea te the che cksum calc ulator obj ect This o bject will log all t he data wh ich is use to calcul ate | |
| 50 | * the check sum to a f ile | |
| 51 | * | |
| 52 | * @param na me | |
| 53 | * @throws I OException | |
| 54 | * / | |
| 55 | pu blic Check sumCalcula tor(String regionNam e) throws STSExcepti on { | |
| 56 | ||
| 57 | Stri ng modifie dRegionNam e = region Name.repla ceAll("[^a -zA-Z0-9 ] ", ""); | |
| 58 | modi fiedRegion Name = mod ifiedRegio nName.subs tring(0, | |
| 59 | Math.min (modifiedR egionName. length(), MAX_FILE_N AME_LENGTH )); | |
| 60 | ||
| 61 | try { | |
| 62 | // Det ermine of the 'check sum' direc tory exist s | |
| 63 | boolea n checksum DirExists = (new Fil e(CHECKSUM _DIR)).exi sts(); | |
| 64 | if (!c hecksumDir Exists) { | |
| 65 | // The d irectory d oesn't exi st so crea te it | |
| 66 | new File (CHECKSUM_ DIR).mkdir (); | |
| 67 | } | |
| 68 | ||
| 69 | // Det ermine if the direct ory alread y exists | |
| 70 | boolea n director yExists = (new File( CHECKSUM_D IR + "/" + modifiedR egionName) ).exists() ; | |
| 71 | if (!d irectoryEx ists) { | |
| 72 | // The d irectory d oesn't exi st so crea te it | |
| 73 | new File (CHECKSUM_ DIR + "/" + modified RegionName ).mkdir(); | |
| 74 | } | |
| 75 | ||
| 76 | // Wri te the fil e to the p ath | |
| 77 | FileWr iter fileW riter = ne w FileWrit er(CHECKSU M_DIR + "/ " + modifi edRegionNa me + "/" + modifiedR egionName | |
| 78 | + FILE_APP END_NAME + FILE_EXTE NSION); | |
| 79 | ||
| 80 | // Use a buffere d writer | |
| 81 | this.b ufferWrite r = new Bu fferedWrit er(fileWri ter); | |
| 82 | } ca tch (IOExc eption e1) { | |
| 83 | throw new STSExc eption(e1) ; | |
| 84 | } | |
| 85 | ||
| 86 | try { | |
| 87 | // get MD5 messa ge digest | |
| 88 | this.a ppmd5 = Me ssageDiges t.getInsta nce("MD5") ; | |
| 89 | } ca tch (NoSuc hAlgorithm Exception e) { | |
| 90 | e.prin tStackTrac e(); | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | /* * | |
| 95 | * Constucto r to creat e the chec ksum calcu lator obje ct This ob ject will log all th e data whi ch is use to calcula te | |
| 96 | * the check sum to a f ile | |
| 97 | * | |
| 98 | * @param na me | |
| 99 | * @param da tastreamFi lePrefix | |
| 100 | * Optional file name prefix | |
| 101 | * @throws I OException | |
| 102 | * / | |
| 103 | pu blic Check sumCalcula tor(String regionNam e, String datastream FilePrefix ) throws S TSExceptio n { | |
| 104 | ||
| 105 | Stri ng modifie dRegionNam e = region Name.repla ceAll("[^a -zA-Z0-9 ] ", ""); | |
| 106 | modi fiedRegion Name = mod ifiedRegio nName.subs tring(0, | |
| 107 | Math.min (modifiedR egionName. length(), MAX_FILE_N AME_LENGTH )); | |
| 108 | ||
| 109 | try { | |
| 110 | // Det ermine of the 'check sum' direc tory exist s | |
| 111 | boolea n checksum DirExists = (new Fil e(CHECKSUM _DIR)).exi sts(); | |
| 112 | if (!c hecksumDir Exists) { | |
| 113 | // The d irectory d oesn't exi st so crea te it | |
| 114 | new File (CHECKSUM_ DIR).mkdir (); | |
| 115 | } | |
| 116 | ||
| 117 | // Det ermine if the direct ory alread y exists | |
| 118 | boolea n director yExists = (new File( CHECKSUM_D IR + "/" + modifiedR egionName) ).exists() ; | |
| 119 | if (!d irectoryEx ists) { | |
| 120 | // The d irectory d oesn't exi st so crea te it | |
| 121 | new File (CHECKSUM_ DIR + "/" + modified RegionName ).mkdir(); | |
| 122 | } | |
| 123 | ||
| 124 | // Wri te the fil e to the p ath | |
| 125 | String filePrefi x = (datas treamFileP refix != n ull && dat astreamFil ePrefix.le ngth() > 0 ) | |
| 126 | ? datastre amFilePref ix + "_" : ""; | |
| 127 | FileWr iter fileW riter = ne w FileWrit er(CHECKSU M_DIR + "/ " + modifi edRegionNa me + "/" + filePrefi x | |
| 128 | + modified RegionName + FILE_AP PEND_NAME + FILE_EXT ENSION); | |
| 129 | ||
| 130 | // Use a buffere d writer | |
| 131 | this.b ufferWrite r = new Bu fferedWrit er(fileWri ter); | |
| 132 | } ca tch (IOExc eption e1) { | |
| 133 | throw new STSExc eption(e1) ; | |
| 134 | } | |
| 135 | ||
| 136 | try { | |
| 137 | // get MD5 messa ge digest | |
| 138 | this.a ppmd5 = Me ssageDiges t.getInsta nce("MD5") ; | |
| 139 | } ca tch (NoSuc hAlgorithm Exception e) { | |
| 140 | e.prin tStackTrac e(); | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | /* * | |
| 145 | * Write the data use to calcula te the che cksum to a file | |
| 146 | * | |
| 147 | * @param da ta | |
| 148 | * @throws I OException | |
| 149 | * / | |
| 150 | pu blic void write(Stri ng data) t hrows STSE xception { | |
| 151 | if ( appmd5 != null) { | |
| 152 | appmd5 .update(da ta.getByte s()); | |
| 153 | } | |
| 154 | ||
| 155 | try { | |
| 156 | buffer Writer.wri te(data); | |
| 157 | } ca tch (IOExc eption e) { | |
| 158 | throw new STSExc eption(e); | |
| 159 | } | |
| 160 | } | |
| 161 | ||
| 162 | /* * | |
| 163 | * Closes th e file whi ch is use to log dat a which is use to ca lculate th e checksum | |
| 164 | * | |
| 165 | * @throws I OException | |
| 166 | * / | |
| 167 | pu blic void close() th rows STSEx ception { | |
| 168 | ||
| 169 | try { | |
| 170 | buffer Writer.clo se(); | |
| 171 | } ca tch (IOExc eption e) { | |
| 172 | throw new STSExc eption(); | |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 176 | /* * | |
| 177 | * Returns t he checksu m of the d ata that w as written to the fi le | |
| 178 | * | |
| 179 | * @return C hecksum st ring | |
| 180 | * / | |
| 181 | pu blic Strin g getCheck sum() { | |
| 182 | byte [] appHash = new byt e[0]; | |
| 183 | if ( appmd5 != null) { | |
| 184 | appHas h = appmd5 .digest(); | |
| 185 | } | |
| 186 | ||
| 187 | retu rn byteArr ayToHexStr ing(appHas h); | |
| 188 | } | |
| 189 | ||
| 190 | /* * | |
| 191 | * Convert a byte[] ar ray to rea dable stri ng format. This make s the "hex " readable ! | |
| 192 | * | |
| 193 | * @return r esult Stri ng buffer in String format | |
| 194 | * @param in | |
| 195 | * byte[] b uffer to c onvert to string for mat | |
| 196 | * / | |
| 197 | pu blic stati c String b yteArrayTo HexString( byte in[]) { | |
| 198 | byte ch = 0x00 ; | |
| 199 | int i = 0; | |
| 200 | if ( in == null || in.len gth <= 0) | |
| 201 | return null; | |
| 202 | ||
| 203 | Stri ng pseudo[ ] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; | |
| 204 | Stri ngBuffer o ut = new S tringBuffe r(in.lengt h * 2); | |
| 205 | ||
| 206 | whil e (i < in. length) { | |
| 207 | ch = ( byte) (in[ i] & 0xF0) ; // Strip off high nibble | |
| 208 | ch = ( byte) (ch >>> 4); | |
| 209 | // shi ft the bit s down | |
| 210 | ch = ( byte) (ch & 0x0F); | |
| 211 | // mus t do this is high or der bit is on! | |
| 212 | out.ap pend(pseud o[ch]); // convert t he nibble to a Strin g | |
| 213 | // Cha racter | |
| 214 | ch = ( byte) (in[ i] & 0x0F) ; // Strip off low n ibble | |
| 215 | out.ap pend(pseud o[ch]); // convert t he nibble to a Strin g | |
| 216 | // Cha racter | |
| 217 | i++; | |
| 218 | } | |
| 219 | Stri ng rslt = new String (out); | |
| 220 | ||
| 221 | retu rn rslt; | |
| 222 | } | |
| 223 | ||
| 224 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.