adding rasika. On Mon, Mar 2, 2015 at 11:21 AM, Tharindu Dharmarathna <tharin...@wso2.com> wrote:
> Hi Sajith, > > Thank you for your response . As done offline chat with Rasika he come up > with a good one without using md5sum we can do same thing from > org.apache.commons.io.IOUtils class in apache, from there we can check > two input streams are same by contentEquals method. > > Documentation for this class > https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/IOUtils.html > > On Mon, Mar 2, 2015 at 11:08 AM, Sajith Ariyarathna <sajit...@wso2.com> > wrote: > >> Hi Tharindu, >> >> I think this is caused by "chunking" in input streams. It might happen >> because of HTTP protocol or a bug in Java, I'm not sure. >> >> As an alternative solution you can run the MD5 command and compare its >> output. Like this, >> >> >> public String getMd5Checksum(String filePath) throws IOException { >> >> final String md5Command = "md5sum "; // Linux 'md5sum', MacOS 'md5' >> >> Process p = Runtime.getRuntime().exec(md5Command + filePath); >> Scanner scn = new Scanner(p.getInputStream()); >> String rv = scn.nextLine(); >> scn.close(); >> return rv; >> } >> >> >> >> >> >> On Sun, Mar 1, 2015 at 2:28 PM, Tharindu Dharmarathna <tharin...@wso2.com >> > wrote: >> >>> Hi Iqbal, >>> >>> I checked those two files manually I got same hash value to two files. >>> This happens in random manner when running the tests >>> >>> >>> On Sun, Mar 1, 2015 at 1:48 PM, Rasika Perera <rasi...@wso2.com> wrote: >>> >>>> Hi Tharindu, >>>> >>>> I checked your `readMD5(InputStream inputStream)` method and it is >>>> working as expected. The problem is with the inputStream you are passing >>>> into the method. >>>> >>>> Please verify that you are not passing the *same inputStream* on the >>>> second time. Because once it is utilized pos has reached the end. So, the >>>> second time you are creating a hash of an empty stream. >>>> >>>> On Sun, Mar 1, 2015 at 1:41 PM, Irham Iqbal <iq...@wso2.com> wrote: >>>> >>>>> Hi Tharindu >>>>> >>>>> Did you try to hash those files manually ? >>>>> If not try to hash those files manually(i.e *md5sum file.txt) *and >>>>> check hash values are same >>>>> >>>>> Thanks, >>>>> Iqbal >>>>> >>>>> >>>>> >>>>> On Sun, Mar 1, 2015 at 12:30 PM, Tharindu Dharmarathna < >>>>> tharin...@wso2.com> wrote: >>>>> >>>>>> Hi all, >>>>>> >>>>>> I wrote test case on APIDocDownload for the API Manager .When I Run >>>>>> the tests It gives me two md5sums for equal files . >>>>>> >>>>>> here's the code sample I write to get md5 value from the files >>>>>> >>>>>> private String readMD5(InputStream inputStream) throws >>>>>>> NoSuchAlgorithmException, IOException { >>>>>>> MessageDigest md = MessageDigest.getInstance("MD5"); >>>>>>> byte[] dataBytes = new byte[1024]; >>>>>>> int read; >>>>>>> try { >>>>>>> while ((read = inputStream.read(dataBytes)) != -1) { >>>>>>> md.update(dataBytes, 0, read); >>>>>>> } >>>>>>> } catch (IOException e) { >>>>>>> log.error("File couldn't found to read md5", e); >>>>>>> throw e; >>>>>>> } finally { >>>>>>> inputStream.close(); >>>>>>> } >>>>>>> byte[] mdBytes = md.digest(); >>>>>>> //convert the byte to hex format >>>>>>> StringBuilder sb = new StringBuilder(); >>>>>>> for (byte mdByte : mdBytes) { >>>>>>> sb.append(Integer.toString((mdByte & 0xff) + 0x100, >>>>>>> 16).substring(1)); >>>>>>> } >>>>>>> return sb.toString(); >>>>>>> } >>>>>> >>>>>> Is there any best way to get two files are identical ?. >>>>>> >>>>>> Thanks >>>>>> >>>>>> -- >>>>>> >>>>>> *Tharindu Dharmarathna*Associate Software Engineer >>>>>> WSO2 Inc.; http://wso2.com >>>>>> lean.enterprise.middleware >>>>>> >>>>>> mobile: *+94779109091 <%2B94779109091>* >>>>>> >>>>>> _______________________________________________ >>>>>> Dev mailing list >>>>>> Dev@wso2.org >>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Irham Iqbal >>>>> Software Engineer - Test Automation >>>>> WSO2, Inc.: http://wso2.com >>>>> lean. enterprise. middleware >>>>> phone: +94 777888452 >>>>> >>>>> _______________________________________________ >>>>> Dev mailing list >>>>> Dev@wso2.org >>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>>> >>>>> >>>> >>>> >>>> -- >>>> With Regards, >>>> >>>> *Rasika Perera* >>>> Software Engineer >>>> M: +94 71 680 9060 E: rasi...@wso2.com >>>> LinkedIn: http://lk.linkedin.com/in/rasika90 >>>> >>>> WSO2 Inc. www.wso2.com >>>> lean.enterprise.middleware >>>> >>> >>> >>> >>> -- >>> >>> *Tharindu Dharmarathna*Associate Software Engineer >>> WSO2 Inc.; http://wso2.com >>> lean.enterprise.middleware >>> >>> mobile: *+94779109091 <%2B94779109091>* >>> >>> _______________________________________________ >>> Dev mailing list >>> Dev@wso2.org >>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>> >>> >> >> >> -- >> Sajith Ariyarathna >> Software Engineer; WSO2, Inc.; http://wso2.com/ >> mobile: +94 77 6602284, +94 71 3951048 >> > > > > -- > > *Tharindu Dharmarathna*Associate Software Engineer > WSO2 Inc.; http://wso2.com > lean.enterprise.middleware > > mobile: *+94779109091 <%2B94779109091>* > -- *Tharindu Dharmarathna*Associate Software Engineer WSO2 Inc.; http://wso2.com lean.enterprise.middleware mobile: *+94779109091*
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev