Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes



3 answers

Permanent link
Yes, you need to read the file contents pass it to the
IFileContentManager.storeContent(...)

as byte array.

Yes, it would be nice to have an API to handle the sandbox files directly but there isn't a public API for that. The other alternative is to invoke lscm commands from your program.

1 vote


Permanent link
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);

0 votes


Permanent link
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?



0 votes

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!

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,934
× 411
× 89
× 56

Question asked: Aug 19 '13, 4:34 p.m.

Question was seen: 8,198 times

Last updated: Apr 12 '21, 11:40 a.m.

Confirmation Cancel Confirm