I have to submit an XML file in Perforce Server. The value of an XML tag can be formed in any language like English, Japanese, Chinese etc. But when I add Japanese or Chinese language then the file type becomes binary instead of text. That's because the Perforce Server identifies binary and text files based on whether it detects non-text characters in the first 8192 bytes of the file.
After studying, I knew that there is a term called p4 typemap which can be used to override the default logic of auto detection of file type.
Reference: https://community.perforce.com/s/article/3454
But the problem is that this solution is from p4v and terminal based but i want to know is there any way to do this programmatically?
You don't necessarily need a typemap to do this; you can also specify a filetype as a parameter to the p4 add
command, e.g.:
p4 add -t binary blahblah.xml
If you have some XML files that are Unicode/binary and some that are ASCII, it makes more sense to specify this on a per-file basis rather than trying to capture it in a typemap. The typemap is meant to be set up ahead of time by the admin to represent common overrides, not modified on the fly by applications.
To convert p4 commands/options into Java code, see the P4 Java API doc: