Skip to main content
Jump to: navigation, search

Scout/HowTo/3.7/Use RemoteFileService

< Scout‎ | HowTo‎ | 3.7
Revision as of 11:38, 15 December 2011 by Bertinrid.gmail.com (Talk | contribs) (New page: With RemoteFileService you can load files from the server to the client. Before using the remote file service, for security reasons, the server has to know what the root directory is wher...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

With RemoteFileService you can load files from the server to the client.

Before using the remote file service, for security reasons, the server has to know what the root directory is where to load the files from. You can configure this setting in the config.ini of the server.

org.eclipse.scout.rt.server.services.common.file.RemoteFileService#rootPath=D:/

For example, there are some files in the directory D:\mydocuments

Get one file

RemoteFile file = SERVICES.getService(IRemoteFileService.class).getRemoteFile(new RemoteFile("mydocuments", "document1.txt", 0l));
try {
   System.out.println(file.getName());
   System.out.println(new String(file.extractData()));
}
   catch (IOException e) {
   e.printStackTrace(
}

It will print the name and the contents of the file.

Get all the files in a directory

RemoteFile[] files = SERVICES.getService(IRemoteFileService.class).getRemoteFiles("mydocuments", new NoFilenameFilter(), null);
for (int i = 0; i < files.length; i++) {
  System.out.println(files[i].getName());
  try {
    System.out.println(new String(files[i].extractData()));
  }
  catch (IOException e) {
    e.printStackTrace();
  }
}

the second parameter in the call is a instance of java.io.FilenameFilter

import java.io.File;
import java.io.FilenameFilter;
import java.io.Serializable; 

public class NoFilenameFilter implements FilenameFilter, Serializable {
  @Override
  public boolean accept(File dir, String name) {
    return true;
  }
}

Create such a class and put it in the shared plug-in. Because this instance of FilenameFilter does not filter at all, the code above will print all the filenames. Be aware that it also loads all the contents of the files, so getting a lot of files will result in an out of memory soon.

Back to the top