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*
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to