Skip to content
Snippets Groups Projects
Commit 5ea3b2ed authored by Arthur Coolen's avatar Arthur Coolen
Browse files

BugID: 604

added file upload and download
parent cf195576
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,8 @@
package nl.astron.lofar.sas.otb.jotdb2;
import java.rmi.registry.*;
import java.rmi.server.RMISocketFactory;
import nl.astron.lofar.lofarutils.remoteFileAdapter;
import nl.astron.lofar.lofarutils.remoteFileInterface;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
......@@ -36,6 +38,7 @@ public class jOTDBserver {
private static jTreeValueAdapter jTreeValueAdapter;
private static jConverter jConverterAdaptee;
private static jConverterAdapter jConverterAdapter;
private static remoteFileAdapter remoteFileAdapter;
static
{
......@@ -141,6 +144,23 @@ public class jOTDBserver {
localRegistry.rebind(jConverterInterface.SERVICENAME, jConverterAdapter);
logger.info("Published jConverterInterface as service " + jConverterInterface.SERVICENAME + ". Ready...");
// Export remoteFile
remoteFileAdapter = new remoteFileAdapter(remoteFileInterface.SERVICENAME);
//A custom port was specified, export the object using the port specified
if(objectPort!=0){
remoteFileAdapter.unexportObject(remoteFileAdapter,true);
remoteFileAdapter.exportObject(remoteFileAdapter,objectPort);
}
logger.info("jOTDBserver publishing service " + remoteFileInterface.SERVICENAME + " in local registry...");
localRegistry.rebind(remoteFileInterface.SERVICENAME, remoteFileAdapter);
logger.info("Published remoteFileInterface as service " + remoteFileInterface.SERVICENAME + ". Ready...");
String statusmessage = "jOTDBserver is ready for incoming calls";
if (args.length > 4) {
Integer rmiPort = new Integer(args[4]);
......
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.rmi.Naming;
import nl.astron.lofar.lofarutils.remoteFileInterface;
public class tRemoteFile {
public static String RMIRegistryName = remoteFileInterface.SERVICENAME;
public static void main(String[] argv) {
if(argv.length != 3) {
System.out.println("Usage: java tRemoteFile fileName machineName machinePort");
System.out.println("Where file is a file on the client.");
System.exit(0);
}
String aRF="rmi://"+argv[1]+":"+argv[2]+"/"+RMIRegistryName;
try {
// do the test
System.out.println("Starting...");
remoteFileInterface fi = (remoteFileInterface) Naming.lookup(aRF);
System.out.println("Starting upload");
File aFile = new File(argv[0]);
byte uldata[] = new byte[(int)aFile.length()];
System.out.println("File opened: "+aFile.getName()+" bytesize: "+ uldata.length);
BufferedInputStream input = new BufferedInputStream(new FileInputStream(aFile));
input.read(uldata,0,uldata.length);
input.close();
if (fi.uploadFile(uldata,argv[0]+".uploaded")) {
System.out.println("upload finished");
} else {
System.out.println("upload failed");
}
System.out.println("Starting download");
byte[] dldata = fi.downloadFile(argv[0]+".uploaded");
File file = new File(argv[0]+".downloaded");
System.out.println("opening File: "+file.getName());
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file.getName()));
System.out.println("Received buffer length: "+dldata.length);
output.write(dldata,0,dldata.length);
output.flush();
output.close();
System.out.println("Download finished");
} catch(Exception e) {
System.err.println("FileServer exception: "+ e.getMessage());
e.printStackTrace();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment