It's all about the answers!

Ask a question

Adding a binary file using Java API


K M (38324449) | asked Jul 21 '10, 9:27 a.m.
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



permanent link
K M (38324449) | answered Jul 22 '10, 12:35 p.m.
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);

permanent link
K M (38324449) | answered Jul 22 '10, 2:38 p.m.
There must be a better way??

permanent link
K M (38324449) | answered Jul 23 '10, 10:15 a.m.
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);

Your answer


Register or to post your answer.