Java API extending - add an existing file of Java File type to existing repository workspace
Hello,
We are migrating files from our current repository solution to RTC 4.0.2, and I am in need of an example to convert a Java File type object to IFileItem. Snippet2.java appears to add a file to a repository workspace by creating a new file, but instead, I have a Java File path to an existing file, and I need to add that file to a repository workspace. Would I simply copy my Java File object to an array of bytes (byte[]) and pass to the VersionedContentManagerByteArrayInputStreamPovider constructor? How can I point to that file's path, or is it assumed that the file must exist in the local sandbox (i.e. Eclipse workspace where the command will be invoked)? Any assistance or examples would be much appreciated. Thanks!
Peter
3 answers
Thanks Te-Hsin. I was actually able to add files to the repository workspace by converting the File to byte[]. I am able to add all file types with the exception of archive (i.e. .zip or .in my case, .bar) files. I'm experimenting with changing the IFileItem content type to allow those adds. It is currently set as follows. Any ideas what needs to change to add .bar, .jar or .zip files?
file.setContentType(IFileItem.CONTENT_TYPE_TEXT);
The exception is not thrown by file.setContentType(IFileItem.CONTENT_TYPE_TEXT) but in the following statement.
IFileContent storedContent = contentManager.storeContent(
IFileContent.ENCODING_US_ASCII,
FileLineDelimiter.LINE_DELIMITER_PLATFORM,
new VersionedContentManagerByteArrayInputStreamPovider(getByte(f, b)), null, monitor);
The .bar (similar to a .jar or .zip) triggers an exception in that statement. Anyone know what property needs to change in that statement to handle .bar/.jar files?
Comments
You should pass in
null
for the encoding and
FileLineDelimiter.LINE_DELIMITER_NONE
as the line delimiter.
Thanks Remy, you definitely helped me get on the right track. Passing null for encoding led to an illegal argument exception. Your recommendation for FileLineDelimiter was correct. The following worked for me. Thanks again!
IFileContent.ENCODING_UTF_16BE,
FileLineDelimiter.LINE_DELIMITER_NONE,
That is very strange. Passing in null with FileLineDelimiter.LINE_DELIMITER_NONE should work. What did the IllegalArgumentException say?
Sorry, it was TeamRepositoryException thrown by the later wkspc.commit call.
TeamRepositoryException: File TestFile.bar must supply a character encoding since the media type is text
So your recommendation of null for encoding does work, as long as I change the following setContentType for archive (.bar, .jar, etc) files (based on the exception message) from CONTENT_TYPE_TEXT to CONTENT_TYPE_UNKNOWN.
file.setContentType(IFileItem.CONTENT_TYPE_UNKNOWN);
Thanks Remy!