It's all about the answers!

Ask a question

How do you retreve file content using Java API


K M (38324950) | asked Apr 28 '10, 10:01 a.m.
How do you retrieve file content.

this is what I have so far, I don't know if it is right

// Stream component branch_build_info.txt
IConfiguration fred = (IConfiguration) stream.configuration(component);

// Map folders = fred.childEntriesForRoot(MONITOR);

IFolderHandle root = fred.rootFolderHandle(MONITOR);
IVersionableHandle pathHandle = fred.resolvePath(root,nameSegments, MONITOR);
if (pathHandle != null) {

System.out.println("hi ken " + pathHandle.toString());
//IVersionable a = root.fetchCompleteItem(pathHandle, MONITOR);

UUID file = pathHandle.getItemId();


System.out.println("hi ken " + file.toString());
}

One answer



permanent link
K M (38324950) | answered Apr 29 '10, 9:02 a.m.
public void updateVersions(IWorkspaceConnection stream,IComponentHandle component,IBaselineHandle baseline) throws TeamRepositoryException {
IFileItem fileItem = null;
IFileContentManager contentManager = FileSystemCore.getContentManager(repo);
String nameSegments[] = {"build_info.txt"};

// Create tmp output file
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("branch.tmp");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}

// Find file handle
IConfiguration iconfig = (IConfiguration) stream.configuration(component);
IFolderHandle root = iconfig.rootFolderHandle(MONITOR);
IVersionableHandle filePathHandle = iconfig.resolvePath(root,nameSegments, MONITOR);

// Check if file found
if (filePathHandle == null) {
throw new TeamRepositoryException("Could not find file " + nameSegments);
}

// Fetch file complete item
IVersionable filePath = (IVersionable) iconfig.fetchCompleteItem(filePathHandle, MONITOR);
if (filePath.hasFullState()) {
fileItem = (IFileItem) filePath.getFullState();
} else {
throw new TeamRepositoryException("Could not find file " + nameSegments + " item");
}

// Get file content
IFileContent content = fileItem.getContent();
contentManager.retrieveContent(fileItem, content, outputStream, MONITOR);

Your answer


Register or to post your answer.