package com.imis.storageconnector.tester;
import java.io.IOException;
import java.text.MessageFormat;
import com.imis.storageconnector.Storage;
import com.imis.storageconnector.StorageConnector;
import com.imis.storageconnector.StorageConnectorException;
public class Program
{
/**
* Retrieves object from IMiS/ARC Storage Server to the local file system.
* @param host an IMiS/ARC Storage Server host.
* @param port an IMiS/ARC Storage Server port.
* @param objectId the IMiS/ARC Storage Server object identifier.
* @return The file path of the retrieved object.
*/
static String retrieveObjectFromIMiSARC(String host, int port, String objectId)
throws StorageConnectorException, IOException
{
String fileName = "";
// Get an instance of the IMiS/Storage Connector
StorageConnector sc = StorageConnector.getInstance();
try
{
// Open IMiS/ARC storage
Storage stg = sc.openIMiSARCStorage(host, port);
try
{
// Retrieve IMiS/ARC object to temporary file
fileName = stg.retrieveObject(objectId);
}
finally
{
// Close IMiS/ARC storage
stg.close();
stg = null;
}
}
finally
{
// Release IMiS/Storage Connector instance
sc = null;
StorageConnector.freeInstance();
}
return fileName;
}
/**
* @param args
*/
public static void main(String[] args)
{
try
{
// Get host and port and object id from command line arguments
String host = args[0];
int port = Integer.parseInt(args[1]);
String objId = args[2];
// Retrieves object from IMiS/ARC to a local file
String fileName = retrieveObjectFromIMiSARC(host, port, objId);
// Execute local file with associated application
Runtime.getRuntime().exec("cmd /c " + fileName);
}
catch (Exception ex)
{
// Show error message
System.out.println(MessageFormat.format("ErrorMessage = {0}",
new Object[] { ex.getMessage() }));
}
}
}
|