FileDocCategorySizeDatePackage
HDF.javaAPI DocAndroid 1.5 API12956Wed May 06 22:41:10 BST 2009org.clearsilver

HDF

public class HDF extends Object
This class is a wrapper around the HDF C API. Many features of the C API are not yet exposed through this wrapper.

Fields Summary
long
hdfptr
HDF
root
private CSFileLoader
fileLoader
Constructors Summary
public HDF()
Constructs an empty HDF dataset

    JNI.loadLibrary();
  
    hdfptr = _init();
    root = null;
  
private HDF(long hdfptr, HDF parent)
Constructs an HDF child node. Used by other methods in this class when a child node needs to be constructed.

    this.hdfptr = hdfptr;
    this.root = (parent.root != null) ? parent.root : parent;
  
Methods Summary
private static native void_copy(long destptr, java.lang.String hdfpath, long srcptr)

private static native void_dealloc(long ptr)

private static native java.lang.String_dump(long ptr)

private static native long_getChild(long ptr, java.lang.String hdfpath)

private static native int_getIntValue(long ptr, java.lang.String hdfname, int default_value)

private static native long_getObj(long ptr, java.lang.String hdfpath)

private static native java.lang.String_getValue(long ptr, java.lang.String hdfname, java.lang.String default_value)

private static native long_init()

private static native long_objChild(long ptr)

private static native java.lang.String_objName(long ptr)

private static native long_objNext(long ptr)

private static native java.lang.String_objValue(long ptr)

private native boolean_readFile(long ptr, java.lang.String filename, boolean use_cb)

private static native boolean_readString(long ptr, java.lang.String data)

private static native void_removeTree(long ptr, java.lang.String hdfname)

private static native void_setSymLink(long ptr, java.lang.String hdf_name_src, java.lang.String hdf_name_dest)

private static native void_setValue(long ptr, java.lang.String hdfname, java.lang.String hdf_value)

private static native boolean_writeFile(long ptr, java.lang.String filename)

private static native boolean_writeFileAtomic(long ptr, java.lang.String filename)

private static native java.lang.String_writeString(long ptr)

public voidclose()
Clean up allocated memory if neccesary. close() allows application to force clean up.

    // Only root nodes have ownership of the C HDF pointer, so only a root
    // node needs to dealloc hdfptr.dir
    if ( root == null) {
      if (hdfptr != 0) {
        _dealloc(hdfptr);
        hdfptr = 0;
      }
    }
  
public voidcopy(java.lang.String hdfpath, org.clearsilver.HDF src)

    if (hdfptr == 0 || src.hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    _copy(hdfptr, hdfpath, src.hdfptr);
  
public java.lang.Stringdump()
Generates a string representing the content of the HDF tree rooted at this node.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _dump(hdfptr);
  
public voidexportDate(java.lang.String hdfname, java.util.TimeZone timeZone, java.util.Date date)
Export a date to a clearsilver tree using a specified timezone

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }

    Calendar cal = Calendar.getInstance(timeZone);
    cal.setTime(date);

    String sec = Integer.toString(cal.get(Calendar.SECOND));
    setValue(hdfname + ".sec", sec.length() == 1 ? "0" + sec : sec);

    String min = Integer.toString(cal.get(Calendar.MINUTE));
    setValue(hdfname + ".min", min.length() == 1 ? "0" + min : min);

    setValue(hdfname + ".24hour",
             Integer.toString(cal.get(Calendar.HOUR_OF_DAY)));
    // java.util.Calendar uses represents 12 o'clock as 0
    setValue(hdfname + ".hour",
             Integer.toString(
                 cal.get(Calendar.HOUR) == 0 ? 12 : cal.get(Calendar.HOUR)));
    setValue(hdfname + ".am",
             cal.get(Calendar.AM_PM) == Calendar.AM ? "1" : "0");
    setValue(hdfname + ".mday",
             Integer.toString(cal.get(Calendar.DAY_OF_MONTH)));
    setValue(hdfname + ".mon",
             Integer.toString(cal.get(Calendar.MONTH)+1));
    setValue(hdfname + ".year",
             Integer.toString(cal.get(Calendar.YEAR)));
    setValue(hdfname + ".2yr",
             Integer.toString(cal.get(Calendar.YEAR)).substring(2));
    setValue(hdfname + ".wday",
             Integer.toString(cal.get(Calendar.DAY_OF_WEEK)));

    boolean tzNegative = timeZone.getRawOffset() < 0;
    int tzAbsolute = java.lang.Math.abs(timeZone.getRawOffset()/1000);
    String tzHour = Integer.toString(tzAbsolute/3600);
    String tzMin = Integer.toString(tzAbsolute/60 - (tzAbsolute/3600)*60);
    String tzString = (tzNegative ? "-" : "+")
                      + (tzHour.length() == 1 ? "0" + tzHour : tzHour)
                      + (tzMin.length() == 1 ? "0" + tzMin : tzMin);
    setValue(hdfname + ".tzoffset", tzString);
  
public voidexportDate(java.lang.String hdfname, java.lang.String tz, int tt)
Export a date to a clearsilver tree using a specified timezone

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }

    TimeZone timeZone = TimeZone.getTimeZone(tz);

    if (timeZone == null) {
      throw new RuntimeException("Unknown timezone: " + tz);
    }

    Date date = new Date((long)tt * 1000);

    exportDate(hdfname, timeZone, date);
  
protected java.lang.StringfileLoad(java.lang.String filename)

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    CSFileLoader aFileLoader = fileLoader;
    if (aFileLoader == null) {
      throw new NullPointerException("No fileLoader specified.");
    } else {
      String result = aFileLoader.load(this, filename);
      if (result == null) {
        throw new NullPointerException("CSFileLoader.load() returned null");
      }
      return result;
    }
  
protected voidfinalize()
Call close() just in case when deallocating Java object.

    close();
    super.finalize();
  
public org.clearsilver.HDFgetChild(java.lang.String hdfpath)
Retrieves the HDF for the first child of the root of the subtree at hdfpath, or null if no child exists of that path or if the path doesn't exist.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    long obj_ptr = _getChild(hdfptr, hdfpath);
    if ( obj_ptr == 0 ) {
      return null;
    }
    return new HDF(obj_ptr, this);
  
public CSFileLoadergetFileLoader()
Get the file loader in use, if any.

return
the file loader in use.


                   
     
    return fileLoader;
  
public intgetIntValue(java.lang.String hdfname, int default_value)
Retrieves the integer value at the specified path in this HDF node's subtree. If the value does not exist, or cannot be converted to an integer, default_value will be returned.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _getIntValue(hdfptr,hdfname,default_value);
  
public org.clearsilver.HDFgetObj(java.lang.String hdfpath)
Retrieves the HDF object that is the root of the subtree at hdfpath, or null if no object exists at that path.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    long obj_ptr = _getObj(hdfptr, hdfpath);
    if ( obj_ptr == 0 ) {
      return null;
    }
    return new HDF(obj_ptr, this);
  
public org.clearsilver.HDFgetOrCreateObj(java.lang.String hdfpath)
Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    long obj_ptr = _getObj(hdfptr, hdfpath);
    if ( obj_ptr == 0 ) {
      // Create a node
      _setValue(hdfptr, hdfpath, "");
      obj_ptr = _getObj( hdfptr, hdfpath );
      if ( obj_ptr == 0 ) {
        return null;
      }
    }
    return new HDF(obj_ptr, this);
  
public org.clearsilver.HDFgetRootObj()
Return the root of the tree where the current node lies. If the current node is the root, return this.

    return root != null ? root : this;
  
public java.lang.StringgetValue(java.lang.String hdfname, java.lang.String default_value)
Retrieves the value at the specified path in this HDF node's subtree.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _getValue(hdfptr,hdfname,default_value);
  
public org.clearsilver.HDFobjChild()
Returns the child of this HDF node, or null if there is no child. Use this in conjunction with objNext to walk the HDF tree. Every node in the tree can have a value, a child, and a next peer.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    long child_ptr = _objChild(hdfptr);
    if ( child_ptr == 0 ) {
      return null;
    }
    return new HDF(child_ptr, this);
  
public java.lang.StringobjName()
Returns the name of this HDF node. The root node has no name, so calling this on the root node will return null.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _objName(hdfptr);
  
public org.clearsilver.HDFobjNext()
Returns the next sibling of this HDF node, or null if there is no next sibling. Use this in conjunction with objChild to walk the HDF tree. Every node in the tree can have a value, a child, and a next peer.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    long next_ptr = _objNext(hdfptr);
    if ( next_ptr == 0 ) {
      return null;
    }
    return new HDF(next_ptr, this);
  
public java.lang.StringobjValue()
Returns the value of this HDF node, or null if this node has no value. Every node in the tree can have a value, a child, and a next peer.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _objValue(hdfptr);
  
public booleanreadFile(java.lang.String filename)
Loads the contents of the specified HDF file from disk into the current HDF object. The loaded contents are merged with the existing contents.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _readFile(hdfptr, filename, fileLoader != null);
  
public booleanreadString(java.lang.String data)
Parses/loads the contents of the given string as HDF into the current HDF object. The loaded contents are merged with the existing contents.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _readString(hdfptr, data);
  
public voidremoveTree(java.lang.String hdfname)
Remove the specified subtree.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    _removeTree(hdfptr,hdfname);
  
public voidsetFileLoader(CSFileLoader fileLoader)
Set the CS file loader to use

param
fileLoader the file loader that should be used.

    this.fileLoader = fileLoader;
  
public voidsetSymLink(java.lang.String hdf_name_src, java.lang.String hdf_name_dest)
Links the src hdf name to the dest.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    _setSymLink(hdfptr,hdf_name_src,hdf_name_dest);
  
public voidsetValue(java.lang.String hdfname, java.lang.String value)
Sets the value at the specified path in this HDF node's subtree.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    _setValue(hdfptr,hdfname,value);
  
public booleanwriteFile(java.lang.String filename)
Serializes HDF contents to a file (readable by readFile)

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _writeFile(hdfptr, filename);
  
public booleanwriteFileAtomic(java.lang.String filename)
Serializes HDF contents to a file (readable by readFile), but writes the file atomically by writing to a temp file then doing a rename(2) on it.

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _writeFileAtomic(hdfptr, filename);
  
public java.lang.StringwriteString()
Serializes HDF contents to a string (readable by readString)

    if (hdfptr == 0) {
      throw new NullPointerException("HDF is closed.");
    }
    return _writeString(hdfptr);