Hi mayank
I didn't go through your code. I think you didn't use checkout/checkin concept here . Just Follow these steps which i am using—
1: get your file Reference object inwhich you want to add versioning aspect and repositoryService object like this–
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
2: pass this file Reference object and repositoryService object to makeVersionable method–
makeVersionable(RepositoryServiceSoapBindingStub repositoryService, Reference fileRef);
3: then checkout the file. When you will do checkout then Alfresco will create a working copy of the original file
4: get the working copy Reference
5: get the Input stream from the file object and pass this object to convertToByteArray method like this—-
byte[] bytes=ContentUtils.convertToByteArray(stream);
6:then update the content of the working copy using contentService.write(—)
7: then checkin
Hope it'll help.
Regards
Nishant