2002-05-11 14:48:00 +00:00
|
|
|
/*
|
|
|
|
|
* ====================================================================
|
|
|
|
|
* The Apache Software License, Version 1.1
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2000 The Apache Software Foundation. All rights
|
|
|
|
|
* reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
*
|
|
|
|
|
* 3. The end-user documentation included with the redistribution,
|
|
|
|
|
* if any, must include the following acknowledgment:
|
|
|
|
|
* "This product includes software developed by the
|
|
|
|
|
* Apache Software Foundation (http://www.apache.org/)."
|
|
|
|
|
* Alternately, this acknowledgment may appear in the software itself,
|
|
|
|
|
* if and wherever such third-party acknowledgments normally appear.
|
|
|
|
|
*
|
|
|
|
|
* 4. The names "Apache" and "Apache Software Foundation" must
|
|
|
|
|
* not be used to endorse or promote products derived from this
|
|
|
|
|
* software without prior written permission. For written
|
|
|
|
|
* permission, please contact apache@apache.org.
|
|
|
|
|
*
|
|
|
|
|
* 5. Products derived from this software may not be called "Apache",
|
|
|
|
|
* nor may "Apache" appear in their name, without prior written
|
|
|
|
|
* permission of the Apache Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
|
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
* ====================================================================
|
|
|
|
|
*
|
|
|
|
|
* This software consists of voluntary contributions made by many
|
|
|
|
|
* individuals on behalf of the Apache Software Foundation. For more
|
|
|
|
|
* information on the Apache Software Foundation, please see
|
|
|
|
|
* <http://www.apache.org/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
package org.apache.poi.hpsf;
|
|
|
|
|
|
2003-10-31 16:39:05 +00:00
|
|
|
import java.io.*;
|
|
|
|
|
import org.apache.poi.util.HexDump;
|
|
|
|
|
import org.apache.poi.util.LittleEndian;
|
|
|
|
|
|
2002-05-11 14:48:00 +00:00
|
|
|
/**
|
2002-07-17 16:23:22 +00:00
|
|
|
* <p>Represents a class ID (16 bytes). Unlike other little-endian
|
|
|
|
|
* type the {@link ClassID} is not just 16 bytes stored in the wrong
|
|
|
|
|
* order. Instead, it is a double word (4 bytes) followed by two
|
|
|
|
|
* words (2 bytes each) followed by 8 bytes.</p>
|
2002-05-11 14:48:00 +00:00
|
|
|
*
|
2003-08-30 09:13:53 +00:00
|
|
|
* @author Rainer Klute <a
|
|
|
|
|
* href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
|
2002-07-17 16:23:22 +00:00
|
|
|
* @version $Id$
|
|
|
|
|
* @since 2002-02-09
|
2002-05-11 14:48:00 +00:00
|
|
|
*/
|
2002-07-17 16:23:22 +00:00
|
|
|
public class ClassID
|
|
|
|
|
{
|
2002-05-11 14:48:00 +00:00
|
|
|
|
|
|
|
|
/**
|
2002-07-17 16:23:22 +00:00
|
|
|
* <p>The bytes making out the class ID in correct order,
|
|
|
|
|
* i.e. big-endian.</p>
|
|
|
|
|
*/
|
|
|
|
|
protected byte[] bytes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>Creates a {@link ClassID} and reads its value from a byte
|
|
|
|
|
* array.</p>
|
2002-05-11 14:48:00 +00:00
|
|
|
*
|
2002-07-17 16:23:22 +00:00
|
|
|
* @param src The byte array to read from.
|
|
|
|
|
* @param offset The offset of the first byte to read.
|
2002-05-11 14:48:00 +00:00
|
|
|
*/
|
2002-07-17 16:23:22 +00:00
|
|
|
public ClassID(final byte[] src, final int offset)
|
|
|
|
|
{
|
|
|
|
|
read(src, offset);
|
2002-05-11 14:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-22 14:27:16 +00:00
|
|
|
/**
|
|
|
|
|
* <p>Creates a {@link ClassID} and initializes its value with
|
|
|
|
|
* 0x00 bytes.</p>
|
|
|
|
|
*/
|
|
|
|
|
public ClassID()
|
|
|
|
|
{
|
2003-08-02 19:02:28 +00:00
|
|
|
bytes = new byte[LENGTH];
|
|
|
|
|
for (int i = 0; i < LENGTH; i++)
|
|
|
|
|
bytes[i] = 0x00;
|
2003-02-22 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-11 14:48:00 +00:00
|
|
|
|
2003-08-02 19:02:28 +00:00
|
|
|
/** <p>The number of bytes occupied by this object in the byte
|
|
|
|
|
* stream.</p> */
|
|
|
|
|
public static final int LENGTH = 16;
|
2002-05-11 14:48:00 +00:00
|
|
|
|
2003-08-02 19:02:28 +00:00
|
|
|
/**
|
|
|
|
|
* @return The number of bytes occupied by this object in the byte
|
|
|
|
|
* stream.
|
|
|
|
|
*/
|
2002-07-17 16:23:22 +00:00
|
|
|
public int length()
|
|
|
|
|
{
|
2002-05-11 14:48:00 +00:00
|
|
|
return LENGTH;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-19 18:09:26 +00:00
|
|
|
|
2002-07-17 16:23:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>Gets the bytes making out the class ID. They are returned in
|
|
|
|
|
* correct order, i.e. big-endian.</p>
|
2003-08-30 09:13:53 +00:00
|
|
|
*
|
2003-08-02 19:02:28 +00:00
|
|
|
* @return the bytes making out the class ID.
|
2002-07-17 16:23:22 +00:00
|
|
|
*/
|
|
|
|
|
public byte[] getBytes()
|
|
|
|
|
{
|
2003-08-02 19:02:28 +00:00
|
|
|
return bytes;
|
2002-05-19 18:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
2002-05-11 14:48:00 +00:00
|
|
|
|
2002-07-17 16:23:22 +00:00
|
|
|
|
2002-05-11 14:48:00 +00:00
|
|
|
/**
|
2003-02-22 14:27:16 +00:00
|
|
|
* <p>Reads the class ID's value from a byte array by turning
|
|
|
|
|
* little-endian into big-endian.</p>
|
2002-07-17 16:23:22 +00:00
|
|
|
*
|
|
|
|
|
* @param src The byte array to read from
|
2002-05-11 14:48:00 +00:00
|
|
|
*
|
2002-07-17 16:23:22 +00:00
|
|
|
* @param offset The offset within the <var>src</var> byte array
|
|
|
|
|
*
|
|
|
|
|
* @return A byte array containing the class ID.
|
2002-05-11 14:48:00 +00:00
|
|
|
*/
|
2002-07-17 16:23:22 +00:00
|
|
|
public byte[] read(final byte[] src, final int offset)
|
|
|
|
|
{
|
|
|
|
|
bytes = new byte[16];
|
2002-07-17 12:01:50 +00:00
|
|
|
|
2002-07-17 16:23:22 +00:00
|
|
|
/* Read double word. */
|
|
|
|
|
bytes[0] = src[3 + offset];
|
|
|
|
|
bytes[1] = src[2 + offset];
|
|
|
|
|
bytes[2] = src[1 + offset];
|
|
|
|
|
bytes[3] = src[0 + offset];
|
2002-07-17 12:01:50 +00:00
|
|
|
|
2002-07-17 16:23:22 +00:00
|
|
|
/* Read first word. */
|
|
|
|
|
bytes[4] = src[5 + offset];
|
|
|
|
|
bytes[5] = src[4 + offset];
|
2002-07-17 12:01:50 +00:00
|
|
|
|
2002-07-17 16:23:22 +00:00
|
|
|
/* Read second word. */
|
|
|
|
|
bytes[6] = src[7 + offset];
|
|
|
|
|
bytes[7] = src[6 + offset];
|
2002-07-17 12:01:50 +00:00
|
|
|
|
2003-08-02 19:02:28 +00:00
|
|
|
/* Read 8 bytes. */
|
|
|
|
|
for (int i = 8; i < 16; i++)
|
|
|
|
|
bytes[i] = src[i + offset];
|
2002-07-17 12:01:50 +00:00
|
|
|
|
2002-07-17 16:23:22 +00:00
|
|
|
return bytes;
|
2002-05-11 14:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-22 14:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>Writes the class ID to a byte array in the
|
|
|
|
|
* little-endian.</p>
|
|
|
|
|
*
|
|
|
|
|
* @param dst The byte array to write to.
|
|
|
|
|
*
|
|
|
|
|
* @param offset The offset within the <var>dst</var> byte array.
|
|
|
|
|
*
|
2003-08-30 09:13:53 +00:00
|
|
|
* @exception ArrayStoreException if there is not enough room for the class
|
2003-08-02 19:02:28 +00:00
|
|
|
* ID 16 bytes in the byte array after the <var>offset</var> position.
|
2003-02-22 14:27:16 +00:00
|
|
|
*/
|
|
|
|
|
public void write(final byte[] dst, final int offset)
|
2003-08-02 19:02:28 +00:00
|
|
|
throws ArrayStoreException
|
2003-02-22 14:27:16 +00:00
|
|
|
{
|
2003-08-02 19:02:28 +00:00
|
|
|
/* Check array size: */
|
|
|
|
|
if (dst.length < 16)
|
|
|
|
|
throw new ArrayStoreException
|
|
|
|
|
("Destination byte[] must have room for at least 16 bytes, " +
|
|
|
|
|
"but has a length of only " + dst.length + ".");
|
2003-02-22 14:27:16 +00:00
|
|
|
/* Write double word. */
|
2003-08-02 19:02:28 +00:00
|
|
|
dst[0 + offset] = bytes[3];
|
|
|
|
|
dst[1 + offset] = bytes[2];
|
|
|
|
|
dst[2 + offset] = bytes[1];
|
|
|
|
|
dst[3 + offset] = bytes[0];
|
2003-02-22 14:27:16 +00:00
|
|
|
|
|
|
|
|
/* Write first word. */
|
2003-08-02 19:02:28 +00:00
|
|
|
dst[4 + offset] = bytes[5];
|
|
|
|
|
dst[5 + offset] = bytes[4];
|
2003-02-22 14:27:16 +00:00
|
|
|
|
|
|
|
|
/* Write second word. */
|
2003-08-02 19:02:28 +00:00
|
|
|
dst[6 + offset] = bytes[7];
|
|
|
|
|
dst[7 + offset] = bytes[6];
|
2003-02-22 14:27:16 +00:00
|
|
|
|
2003-08-02 19:02:28 +00:00
|
|
|
/* Write 8 bytes. */
|
|
|
|
|
for (int i = 8; i < 16; i++)
|
|
|
|
|
dst[i + offset] = bytes[i];
|
2003-02-22 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-03 20:16:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <p>Checks whether this <code>ClassID</code> is equal to another
|
|
|
|
|
* object.</p>
|
|
|
|
|
*
|
|
|
|
|
* @param o the object to compare this <code>PropertySet</code> with
|
|
|
|
|
* @return <code>true</code> if the objects are equal, else
|
|
|
|
|
* <code>false</code>.</p>
|
|
|
|
|
*/
|
|
|
|
|
public boolean equals(final Object o)
|
|
|
|
|
{
|
|
|
|
|
if (o == null || !(o instanceof ClassID))
|
|
|
|
|
return false;
|
|
|
|
|
final ClassID cid = (ClassID) o;
|
|
|
|
|
if (bytes.length != cid.bytes.length)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 0; i < bytes.length; i++)
|
|
|
|
|
if (bytes[i] != cid.bytes[i])
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-31 16:39:05 +00:00
|
|
|
/**
|
|
|
|
|
* Returns a human readable representation of the Class ID
|
|
|
|
|
* in standard format <code>"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"</code>
|
|
|
|
|
* @return String representation of the Class ID represented
|
|
|
|
|
* by this object.
|
|
|
|
|
*/
|
|
|
|
|
public String toString()
|
|
|
|
|
{
|
|
|
|
|
StringBuffer sbClassId = new StringBuffer( 38);
|
|
|
|
|
sbClassId.append( '{');
|
|
|
|
|
for( int i=0; i < 16; i++) {
|
|
|
|
|
sbClassId.append( HexDump.toHex( bytes[ i]));
|
|
|
|
|
if( i == 3 || i == 5 || i == 7 || i == 9) {
|
|
|
|
|
sbClassId.append( '-');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sbClassId.append( '}');
|
|
|
|
|
return sbClassId.toString();
|
|
|
|
|
}
|
2003-08-30 09:13:53 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see Object#hashCode()
|
|
|
|
|
*/
|
|
|
|
|
public int hashCode()
|
|
|
|
|
{
|
2003-09-13 12:31:28 +00:00
|
|
|
return new String(bytes).hashCode();
|
2003-08-30 09:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
2002-05-11 14:48:00 +00:00
|
|
|
}
|