| Back | Main view

Storing objects on IMiS/ARC with IMiS/Storage Connector JAVA

Product:IMiS/Storage Connector JAVA
Release:2.1.1005
Date:10/12/2011

Case: This article will demonstrate how to use IMiS/Storage Connector JAVA interface to store a file on a local file system as an object on IMiS/ARC Storage Server.

Description:

Storing an object on IMiS/ARC Storage Server with IMiS/Storage Connector is done with the following steps:
1. get an instance of the StorageConnector class
2. open a storage on IMiS/ARC Storage Server specified by the hostname and port
3. use the storeObject method of the Storage class to store a local file as an object on the IMiS/ARC Storage Server.

Notes:
The sample JAVA code provided is a project created using JAVA 1.4.2.18 in Eclipse IDE for Java Developers with a reference to an storageconnector.jar, iarcli.jar and imisbase.jar.
The application gets the IMiS/ARC Storage Server host, port and profile, and an local file path through the command line arguments.


JAVA
 
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() }));
    }
  }
}
 
 

Related Documents:

Database 'IMiS Knowledge database', View 'All Documents', Document 'Retrieving objects from IMiS/ARC with IMiS/Storage Connector JAVA' Retrieving objects from IMiS/ARC with IMiS/Storage Connector JAVA

| Back | Main view