Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 08 Mar 2013 02:54:12 -0600 Date: Fri, 08 Mar 2013 08:54:10 +0000 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: parse output and check if a change References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 55 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-SyLZd/GPbYmBGitszR7tbdwmeWl2QAEQON6J5A96TTk+LJLN+B74hJCL34U+4vUHxLlc8sxgezWodwr!s1+GKYGODcPVx5MDUm1oG1IsetxGQ/H6CILVqwlWOGp+nMlYQ16Y/y6F8CgorXgM9U+CNVtQXh4= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2876 Xref: csiph.com comp.lang.java.programmer:22816 On 07/03/13 19:10, mike wrote: > Hi, > > I am sending a command to unix and then I parse the output. The output is stored in a Info object ( Info.java). This will be used later in application. > > The problem is that the output from the unix command might change. So I want to make sure that if there is a change then we parse and update the Info object. But if there is no change then we do not need to parse and extract the information. We can use the Info object directly. > > The idea I have is to use the output from the command ( a text string) and calculate some kind of hash/md5sum. > > So the next time I run the unix command I take the output (a string) and calculate hash/md5 and see if it is an exact match as was generated the first time. > > Anyone will to give a hint on how to implememt this using java? > > br, > > //mike Just FYI the MessageDigest class has a method to compare two digests Not sure what all this 'converting to hex' is all about, just compare digests. So something like (not tested for syntatic correctness) MessageDigest md = MessageDigest.getInstance("SHA"); //or whatever ... Info info = new Info(); String data = getData(); byte[] dgst = md.digest(data.getBytes()); info.parse(data); info.setDigest(dgst); //later data = getData(); dgst = md.digest(data.getBytes()); if(!MessageDigest.isEqual(dgst, info.getDigest()){ info.parse(data); info.setDigest(dgst); } ... etc What do you think? lipska -- Lipska the KatŠ: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun