Adding a binary file using Java API
I have an example of adding a text file
VersionedContentManagerByteArrayInputStreamPovider inputStream = new VersionedContentManagerByteArrayInputStreamPovider("hello".getBytes()); IFileContent storedContent = contentManager.storeContent(IFileContent.ENCODING_US_ASCII,FileLineDelimiter.LINE_DELIMITER_PLATFORM, inputStream, null, MONITOR); Does anybody have an example of adding a binary file???? |
3 answers
fileStream = new FileInputStream(filename);
final DisposableInputStreamProvider isProvider = TemporaryOutputStream.createLocalBuffer(fileStream,MONITOR); IFileContent storedContent = contentManager.storeContent(IFileContent.ENCODING_UTF_8,FileLineDelimiter.LINE_DELIMITER_NONE, new AbstractVersionedContentManagerInputStreamProvider() { @Override public void dispose() throws IOException, TeamRepositoryException { isProvider.dispose(); } @Override public InputStream getInputStream(int flags) throws IOException, TeamRepositoryException { //it's ok to pass in null, we know the content is cached on local disk return isProvider.getInputStream(null); } @Override public InputStream wrapInputStream(InputStream in) throws IOException, TeamRepositoryException { return in; } } , null, MONITOR); |
|
StringBuffer tmp_buf = new StringBuffer("");
VersionedContentManagerByteArrayInputStreamPovider inputStream = new VersionedContentManagerByteArrayInputStreamPovider (tmp_buf.toString().getBytes(IContent.ENCODING_UTF_8), 0,tmp_buf.length()); IFileContent storedContent = contentManager.storeContent (IFileContent.ENCODING_UTF_8 ,FileLineDelimiter.LINE_DELIMITER_NONE, inputStream, null, MONITOR); |
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.