이 샘플에서는 MVS 파일 시스템에서 파일 컨텐츠(데이터 세트 멤버 또는 순차 데이터 세트)를 검색하는 방법을 보여줍니다.
자원 컨텐츠를 검색하려면 네비게이터에서 자원이 선택되어 있는지 확인하고 API 샘플 > 파일 컨텐츠 가져오기 조치를 선택하십시오.
워크벤치와 연관된 표준 출력에 파일 컨텐츠가 표시됩니다. 워크벤치가 시작된 DOS 창이나 런타임 워크벤치의 경우 워크벤치를 호스트하는 콘솔 보기에서 볼 수 있습니다.

전체 소스 코드는 GetContentsAction.java에 있습니다.
GetContentsAction 클래스의 run 메소드에 있는 다음 코드 스니펫은 MVS 파일 컨텐츠(PDS 멤버 또는 순차 데이터 세트)를 가져오는 방법을 보여줍니다. 이 스니펫에서는 IPhysicalFile과 ILogicalFile이 구별되지만 전체 플로우는 같습니다. 이 코드는 먼저 getContents 메소드를 호출하여 InputStream을 가져옵니다. InputStream을 가져온 후 표준 Java™ 메소드(예: read)를 호출하여 파일 컨텐츠를 검색할 수 있습니다.
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();
}
이 예제는 Eclipse에서 선택사항 변경 이벤트에 대응하는 방법을 보여줍니다. GetContentsAction 클래스는 ISelectionListener 인터페이스를 구현합니다. selectionChanged 메소드 구현은 IStructuredSelection을 참조하는 이벤트에 대응합니다. 일반적으로 이는 트리 네비게이터의 현재 선택사항이 변경되면 발생합니다. 예제 코드는 현재 선택사항과 연관된 반복자를 사용하고 각 항목을 목록에 추가하여 현재 선택사항에 포함된 모든 항목을 반복합니다.
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);
}
}
}