it.tidalwave.imageio.raw
Class Directory

java.lang.Object
  extended by it.tidalwave.imageio.raw.Directory
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
IFDSupport

public abstract class Directory
extends java.lang.Object
implements java.io.Serializable

Version:
CVS $Id: Directory.java,v 1.4 2006/02/08 22:32:01 fabriziogiudici Exp $
Author:
Fabrizio Giudici
See Also:
Serialized Form

Nested Class Summary
static class Directory.Enumeration
          This class models an enumerated value for a tag.
 
Field Summary
protected  long end
           
 Directory nextDirectory
           
protected  long start
           
protected  TagRegistry tagRegistry
          The registry the contained tags belongs to.
 
Constructor Summary
protected Directory()
          For de-serialization only.
protected Directory(TagRegistry tagRegistry)
          Creates a new Directory whose tags belong to the given registry.
 
Method Summary
 void addDirectory(Directory subDirectory)
          Adds a sub-directory.
 void addNamedDirectory(java.lang.String name, Directory subDirectory)
          Adds a named sub-directory.
 void addTag(AbstractTag tag)
          Adds a tag to this Directory.
static double[] asDoubles(TagRational[] rationals)
          Convenience method that converts an array of rationals into doubles.
static float[] asFloats(TagRational[] rationals)
          Convenience method that converts an array of rationals into floats.
 boolean containsTag(java.lang.Object key)
          Checks if this Directory contains a given tag.
 int getByte(java.lang.Object key)
          Returns the tag value as a byte.
 byte[] getBytes(java.lang.Object key)
          Returns the tag values as bytes.
 double getDouble(java.lang.Object key)
          Returns the tag value as a double.
 double[] getDoubles(java.lang.Object key)
          Returns the tag values as doubles.
 long getEnd()
           
 float getFloat(java.lang.Object key)
          Returns the tag value as a float.
 float[] getFloats(java.lang.Object key)
          Returns the tag values as floats.
 int getInteger(java.lang.Object key)
          Returns the tag value as an integer.
 int[] getIntegers(java.lang.Object key)
          Returns the tag values as integers.
 Directory getNamedDirectory(java.lang.String name)
          Returns a named sub-directory
 Directory getNextDirectory()
           
 java.lang.Object getObject(java.lang.Object key)
          FIXME: This method is only provided for supporting it.tidalwave.image.DirectorySupport, but should be replaced with a more decoupled mechanism.
 TagRational getRational(java.lang.Object key)
          Returns the tag value as a rational.
 TagRational[] getRationals(java.lang.Object key)
          Returns the tag values as rationals.
 TagRegistry getRegistry()
          Returns the registry the contained tags belong to.
 long getStart()
           
 java.lang.String getString(java.lang.Object key)
          Returns the tag value as a string.
 java.lang.String[] getSubDirectoryNames()
          Returns the names of named sub directories
 AbstractTag getTag(java.lang.Object key)
          Retrieves a contained tag given its key.
 java.lang.String getTagName(java.lang.Object key)
          Returns the name of the given tag.
abstract  long load(RAWImageInputStream iis, long offset)
           
 void loadAll(RAWImageInputStream iis, long offset)
           
 AbstractTag removeTag(java.lang.Object key)
          Removes a given tag from this Directory
 java.util.Iterator subDirectories()
          Returns an iterator over sub-directories.
 java.util.Collection tags()
          Returns the contained tags in the same order as they were added.
 java.lang.String toString()
           
protected  java.lang.String toString(byte[] array)
           
protected  java.lang.String toString(double[] array)
           
protected  java.lang.String toString(int[] array)
           
protected  java.lang.String toString(TagRational[] array)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

start

protected long start

end

protected long end

nextDirectory

public Directory nextDirectory

tagRegistry

protected transient TagRegistry tagRegistry
The registry the contained tags belongs to. This is transient so that this class can be serialized without carrying along the whole registry! Upon deserialization the link to the registry must be restored by using the registryName.

Constructor Detail

Directory

protected Directory()
For de-serialization only.


Directory

protected Directory(TagRegistry tagRegistry)
Creates a new Directory whose tags belong to the given registry.

Parameters:
tagRegistry - the registry
Method Detail

getRegistry

public TagRegistry getRegistry()
Returns the registry the contained tags belong to.

Returns:
the registry

getStart

public long getStart()

getEnd

public long getEnd()

load

public abstract long load(RAWImageInputStream iis,
                          long offset)
                   throws java.io.IOException
Parameters:
iis -
offset -
Throws:
java.io.IOException

loadAll

public void loadAll(RAWImageInputStream iis,
                    long offset)
             throws java.io.IOException
Parameters:
iis -
offset -
Throws:
java.io.IOException

addTag

public void addTag(AbstractTag tag)
Adds a tag to this Directory.

Parameters:
tag - the tag to add

getTag

public AbstractTag getTag(java.lang.Object key)
Retrieves a contained tag given its key.

Parameters:
key - the tag key

containsTag

public boolean containsTag(java.lang.Object key)
Checks if this Directory contains a given tag.

Parameters:
key - the tag key
Returns:
true if this Directory contains the tag

removeTag

public AbstractTag removeTag(java.lang.Object key)
Removes a given tag from this Directory

Parameters:
key - the tag key
Returns:
the remove tag

getTagName

public java.lang.String getTagName(java.lang.Object key)
Returns the name of the given tag. FIXME: is meaningful here?

Parameters:
key - the tag key
Returns:
the tag name

getObject

public java.lang.Object getObject(java.lang.Object key)
FIXME: This method is only provided for supporting it.tidalwave.image.DirectorySupport, but should be replaced with a more decoupled mechanism. This method returns a plain Number when an enumeration could be expected.


getBytes

public byte[] getBytes(java.lang.Object key)
Returns the tag values as bytes.

Parameters:
key - the tag key
Returns:
the bytes or null if the tag is not present

getByte

public int getByte(java.lang.Object key)
Returns the tag value as a byte.

Parameters:
key - the tag key
Returns:
the byte
Throws:
java.util.NoSuchElementException - if the tag is not present

getRationals

public TagRational[] getRationals(java.lang.Object key)
Returns the tag values as rationals.

Parameters:
key - the tag key
Returns:
the rationals or null if the tag is not present

getRational

public TagRational getRational(java.lang.Object key)
Returns the tag value as a rational.

Parameters:
key - the tag key
Returns:
the rational
Throws:
java.util.NoSuchElementException - if the tag is not present

getDoubles

public double[] getDoubles(java.lang.Object key)
Returns the tag values as doubles.

Parameters:
key - the tag key
Returns:
the doubles or null if the tag is not present

getDouble

public double getDouble(java.lang.Object key)
Returns the tag value as a double.

Parameters:
key - the tag key
Returns:
the double
Throws:
java.util.NoSuchElementException - if the tag is not present

getFloats

public float[] getFloats(java.lang.Object key)
Returns the tag values as floats.

Parameters:
key - the tag key
Returns:
the floats or null if the tag is not present

getFloat

public float getFloat(java.lang.Object key)
Returns the tag value as a float.

Parameters:
key - the tag key
Returns:
the float
Throws:
java.util.NoSuchElementException - if the tag is not present

getIntegers

public int[] getIntegers(java.lang.Object key)
Returns the tag values as integers.

Parameters:
key - the tag key
Returns:
the integers or null if the tag is not present

getInteger

public int getInteger(java.lang.Object key)
               throws java.util.NoSuchElementException
Returns the tag value as an integer.
This method returns 0 if there exists a tag with the given key which contains an empty array of integers. Such a tag is BayerGreenSplit in DNG files. It should be clarified if this is compliant with specs (in which case this behaviour should be extended to other multiple-value getXXX() methods, or if it is a bug of Adobe Converter.

Parameters:
key - the tag key
Returns:
the integer
Throws:
java.util.NoSuchElementException - if the tag is not present

getString

public java.lang.String getString(java.lang.Object key)
Returns the tag value as a string.

Parameters:
key - the tag key
Returns:
the string or null if the tag has not been found

getNextDirectory

public Directory getNextDirectory()

addDirectory

public void addDirectory(Directory subDirectory)
Adds a sub-directory.

Parameters:
subDirectory - the sub-directory

subDirectories

public java.util.Iterator subDirectories()
Returns an iterator over sub-directories. Note that named directories are not returned.

Returns:
the iterator

addNamedDirectory

public void addNamedDirectory(java.lang.String name,
                              Directory subDirectory)
Adds a named sub-directory.

Parameters:
name - the directory name
subDirectory - the sub-directory

getNamedDirectory

public Directory getNamedDirectory(java.lang.String name)
Returns a named sub-directory

Parameters:
name - the sub-directory name
Returns:
the sub-directory

getSubDirectoryNames

public java.lang.String[] getSubDirectoryNames()
Returns the names of named sub directories

Returns:
the subdirectory names

tags

public java.util.Collection tags()
Returns the contained tags in the same order as they were added.

Returns:
the contained tags

asFloats

public static float[] asFloats(TagRational[] rationals)
Convenience method that converts an array of rationals into floats.

Parameters:
rationals -
Returns:
the floats

asDoubles

public static double[] asDoubles(TagRational[] rationals)
Convenience method that converts an array of rationals into doubles.

Parameters:
rationals -
Returns:
the doubles

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

protected java.lang.String toString(byte[] array)

toString

protected java.lang.String toString(int[] array)

toString

protected java.lang.String toString(double[] array)

toString

protected java.lang.String toString(TagRational[] array)