|
|
|
Re: File handling [message #762230 is a reply to message #762029] |
Wed, 07 December 2011 18:36 |
Jeremie Bresson Messages: 124 Registered: November 2010 |
Senior Member |
|
|
This code works for me:
RemoteFile[] files = SERVICES.getService(IRemoteFileService.class).getRemoteFiles("", new AcceptFileFilter(), null);
for (RemoteFile f : files) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
f.writeData(baos);
}
catch (IOException e) {
e.printStackTrace();
}
MessageBox.showOkMessage(f.getName(), baos.toString(), null);
}
AcceptFileFilter is a simple class in Shared implementing FilenameFilter and Serializable. You could have a more complex Filter (for example test that the file is a mp3 file). You can also add field on this class in order to reuse it. Note:
* It is in shared because it has to be available in the client and in the server.
* Serializable because it is "transported" through the Service Tunnel.
import java.io.File;
import java.io.FilenameFilter;
import java.io.Serializable;
public class AcceptFileFilter implements FilenameFilter, Serializable {
private static final long serialVersionUID = 1L;
@Override
public boolean accept(File arg0, String arg1) {
return true;
}
}
Where are the remotes files?
If you have a look a the RemoteFileService you will see that the function getFiles(String, FilenameFilter) uses the private field: m_rootPath to search for files.
This field has a setter: setRootPath(String)
Because this setter is in a Service class, Eclipse Scout supports that you set a value in your server config.ini (more information here: setter in config.ini). This also allows you to have a different configuration for your local development server and your production server.
In config.ini you can set the path for m_rootPath:
### Service Runtime Configuration
org.eclipse.scout.rt.server.services.common.file.RemoteFileService#rootPath=/Users/jebr/remote_files
If you have some text files in the folder defined in your config.ini, you will get some MessageBoxes.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03566 seconds