Retrieving file content
This sample demonstrates how to retrieve the contents of a file (data set member or sequential data set) on the MVS™ file system.
Sample scenario
To retrieve the content for the resource, make sure that the resource is selected in the navigator, then select the API Samples > Get File Contents action.
The contents in the file are displayed in the standard output that is associated with the workbench. The contents can be found in the Console view of the workbench.

Sample code walk-through
The complete source code can be found at GetContentsAction.java.
Reading from the remote artifact
The
following code snippet from the run method of the
class GetContentsAction demonstrates how to obtain
the content of an MVS file (PDS
member or sequential data set). The snippet differentiates between
an IPhysicalFile and an ILogicalFile,
but the overall flow is the same for both. The code first starts the getContents method
to obtain an InputStream. After you have an InputStream,
the standard Java™ methods such
as read can be started to retrieve the content of
the file.
InputStream is = null;
if (selectedItem instanceof ILogicalFile) {
// Project proxy for resource
ILogicalFile file = (ILogicalFile) selectedItem;
filename = file.getName();
is = file.getContents();
} else if (selectedItem instanceof IPhysicalFile) {
// Physical Resource
IPhysicalFile file = (IPhysicalFile) selectedItem;
filename = file.getName();
is = file.getContents();
}
int ch = is.read();
while (ch != -1) {
System.out.write(ch);
ch = is.read();
}Handling selection changed events
This
example also demonstrates how to react to selection change events
in Eclipse. The GetContentsAction class implements
the ISelectionListener interface. Its selectionChanged method
implementation reacts to events that refer to an IStructuredSelection,
typically caused by a change in the current selection in a tree navigator.
The sample code iterates through the items in the current selection
by using an iterator that is associated with it and adding each item
to a list.
public void selectionChanged(IAction action, ISelection selection) {
fTargetList = null;
if (selection instanceof IStructuredSelection) {
fTargetList = new ArrayList();
IStructuredSelection selections = (IStructuredSelection)
selection;
for (Iterator e = selections.iterator(); e.hasNext();) {
Object next = e.next();
fTargetList.add(next);
}
}
}