org.hd.d.pg2k.svrCore
Class ExhibitThumbnails.Thumbnail

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.ExhibitThumbnails.Thumbnail
All Implemented Interfaces:
java.io.ObjectInputValidation, java.io.Serializable
Enclosing class:
ExhibitThumbnails

public static final class ExhibitThumbnails.Thumbnail
extends java.lang.Object
implements java.io.Serializable, java.io.ObjectInputValidation

Immutable, Serializable single thumbnail (standard or small). Implements hashCode() and equals(), with equals() meaning dimensional and byte-for-byte equality.

See Also:
Serialized Form

Field Summary
private  byte[] data
          Thumbnail raw data; non-null, non-zero-length.
private  byte[] hashMD5
          The MD5 hash of the thumbnail data (16 bytes), or null.
private static java.io.ObjectStreamField[] serialPersistentFields
          Mark all mutable members as unshared for safety.
private static long serialVersionUID
          Unique serialisation version number.
private  java.awt.Dimension xyDim
          Image width and height for image thumbnail, both strictly positive or whole object null.
 
Constructor Summary
ExhibitThumbnails.Thumbnail(byte[] _data, java.awt.Dimension _xyDim)
          Construct an image thumbnail with x,y dimensions and a byte array.
 
Method Summary
private  byte[] _computeMD5Hash(byte[] d)
          Compute the MD5 hash of the supplied data; never null.
 boolean equals(java.lang.Object obj)
          For equality the thumbnails must be indistinguishable.
 byte[] getMD5Hash()
          Get the MD5 hash of the thumbnail data; never null.
 java.awt.Dimension getXyDim()
          Get XxY dimension of thumbnail, or null if not appropriate.
 int hashCode()
          The hash code is based on things we can compute very quickly.
 boolean hasMD5Hash()
          True iff this thumbnail has a precomputed MD5hash stored.
private  void readObject(java.io.ObjectInputStream in)
          Deserialise.
 int size()
          Return size of data array.
 byte[] toByteArrray()
          Get data as a (copied) byte[].
 java.lang.String toString()
          Human-readable summary.
 void validateObject()
          Validate fields/state.
 void writeData(java.io.OutputStream os)
          Write data to a stream, avoiding an unnecessary copy in many cases.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialPersistentFields

private static final java.io.ObjectStreamField[] serialPersistentFields
Mark all mutable members as unshared for safety.


data

private final byte[] data
Thumbnail raw data; non-null, non-zero-length.


xyDim

private final java.awt.Dimension xyDim
Image width and height for image thumbnail, both strictly positive or whole object null.


hashMD5

private final byte[] hashMD5
The MD5 hash of the thumbnail data (16 bytes), or null. This is only present (non-null) if computed at source/construction.

This may also be null when deserialised from an old instance before we computed and stored this value.


serialVersionUID

private static final long serialVersionUID
Unique serialisation version number.

See Also:
Constant Field Values
Constructor Detail

ExhibitThumbnails.Thumbnail

public ExhibitThumbnails.Thumbnail(byte[] _data,
                                   java.awt.Dimension _xyDim)
Construct an image thumbnail with x,y dimensions and a byte array. The byte array must not be null nor zero-length. The Dimension object must be non-null and the width and height must be strictly positive.

Both arguments are copied and are not altered.

Method Detail

size

public int size()
Return size of data array.


toByteArrray

public byte[] toByteArrray()
Get data as a (copied) byte[].


writeData

public void writeData(java.io.OutputStream os)
               throws java.io.IOException
Write data to a stream, avoiding an unnecessary copy in many cases. We trust the os.write() method(s) not to alter the data that we pass to it.

Parameters:
os - (safe) OutputStream on which to write the binary data; never null
Throws:
java.io.IOException - if thrown by os

getXyDim

public java.awt.Dimension getXyDim()
Get XxY dimension of thumbnail, or null if not appropriate.


hashCode

public int hashCode()
The hash code is based on things we can compute very quickly. For this we use:

We could use the height and width, but we assume that they may not be very effective in distinguishing between thumbnails as they may be constrained to be fixed in one dimension or the other.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
For equality the thumbnails must be indistinguishable. That is, they must be the same dimensions and their data length must be the same and the data must match byte for byte.

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Human-readable summary.

Overrides:
toString in class java.lang.Object

hasMD5Hash

public boolean hasMD5Hash()
True iff this thumbnail has a precomputed MD5hash stored. If true then getMD5Hash() does not actually have to calculate the hash.

If false then this instance has reduced protection against data corruption.


getMD5Hash

public byte[] getMD5Hash()
Get the MD5 hash of the thumbnail data; never null. If this is stored in the object then we return a copy to the caller, else we return the result of computing it afresh on the data.

Returns:
a private copy of the MD5 hash bytes; never null

_computeMD5Hash

private byte[] _computeMD5Hash(byte[] d)
Compute the MD5 hash of the supplied data; never null. Computed on demand every time.


readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Deserialise.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

validateObject

public void validateObject()
                    throws java.io.InvalidObjectException
Validate fields/state. Called in the constructor and possibly after deserialising.

This only checks that this is good as a standard thumbnail: extra checking may have to be imposed elsewhere for a small thumbnail.

Barf if something bad is found. (Maybe allow some extra info in debug version.)

Specified by:
validateObject in interface java.io.ObjectInputValidation
Throws:
java.io.InvalidObjectException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.