| Back | Main view

Retrieving objects from 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 retrieve an object from IMiS/ARC Storage Server to a temporary file on the local file system.

Description:

Object retrieval 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 retrieveObject method of the Storage class to retrieve a document from the IMiS/ARC Storage Server to a temporary file.

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
{
  /**
   * 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() }));
    }
  }
}
 
Related Documents:

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

| Back | Main view