How do you retreve file content using Java API
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
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
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.