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
{
/**
* Store local file as object on IMiS/ARC Storage Server.
* @param host an IMiS/ARC Storage Server host.
* @param port an IMiS/ARC Storage Server port.
* @param profile an IMiS/ARC Storage Server profile.
* @param fileName the file path of the local file to be stored.
* @return The IMiS/ARC Storage Server object identifier.
* @throws StorageConnectorException if StorageConnectorException occurs.
* @throws IOException if IOException occurs.
*/
static String storeObjectToIMiSARC(String host, int port, String profile, String fileName)
throws StorageConnectorException, IOException
{
String objectId = "";
// Get an instance of the IMiS/Storage Connector
StorageConnector sc = StorageConnector.getInstance();
try
{
// Open storage on IMiS/ARC Storage Server
Storage stg = sc.openIMiSARCStorage(host, port);
try
{
// Store local file as an object on IMiS/ARC
// Remarks: when null or empty mime parameter
// is specified, IMiS/Storage Connector tries
// to resolve the MIME type from the file extension
objectId = stg.storeObject(fileName, profile, null);
}
finally
{
// Close IMiS/ARC storage
stg.close();
stg = null;
}
}
finally
{
// Release IMiS/Storage Connector instance
sc = null;
StorageConnector.freeInstance();
}
return objectId;
}
/**
* @param args
*/
public static void main(String[] args)
{
try
{
String host = args[0];
int port = Integer.parseInt(args[1]);
String profile = args[2];
String fileName = args[3];
// Store local file as object on IMiS/ARC
String objectId = storeObjectToIMiSARC(host, port, profile, fileName);
// Show object identifier
System.out.println(MessageFormat.format("Object stored on IMiS/ARC Storage Server with Id = {0}",
new Object[] { objectId }));
}
catch (Exception ex)
{
// Show error message
System.out.println(MessageFormat.format("ErrorMessage = {0}",
new Object[] { ex.getMessage() }));
}
}
}
|