Made some changes for HDF types
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352453 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f66f109772
commit
6fe733d9b5
@ -183,6 +183,24 @@ public class HexDump
|
|||||||
return _cbuffer;
|
return _cbuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the parameter to a hex value.
|
||||||
|
*
|
||||||
|
* @param value The value to convert
|
||||||
|
* @return A String representing the array of bytes
|
||||||
|
*/
|
||||||
|
public static String toHex(final byte[] value)
|
||||||
|
{
|
||||||
|
StringBuffer retVal = new StringBuffer();
|
||||||
|
retVal.append('[');
|
||||||
|
for(int x = 0; x < value.length; x++)
|
||||||
|
{
|
||||||
|
retVal.append(toHex(value[x]));
|
||||||
|
retVal.append(", ");
|
||||||
|
}
|
||||||
|
retVal.append(']');
|
||||||
|
return retVal.toString();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Converts the parameter to a hex value.
|
* Converts the parameter to a hex value.
|
||||||
*
|
*
|
||||||
|
@ -94,6 +94,18 @@ public class LittleEndian
|
|||||||
return (short) getNumber(data, offset, SHORT_SIZE);
|
return (short) getNumber(data, offset, SHORT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a short array from a byte array.
|
||||||
|
*/
|
||||||
|
public static short[] getSimpleShortArray(final byte[] data, final int offset, final int size)
|
||||||
|
{
|
||||||
|
short[] results = new short[size];
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
results[i] = getShort(data, offset + 2 + (i * 2));
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* get a short array from a byte array. The short array is assumed
|
* get a short array from a byte array. The short array is assumed
|
||||||
* to start with a word describing the length of the array.
|
* to start with a word describing the length of the array.
|
||||||
@ -101,11 +113,7 @@ public class LittleEndian
|
|||||||
public static short[] getShortArray(final byte[] data, final int offset)
|
public static short[] getShortArray(final byte[] data, final int offset)
|
||||||
{
|
{
|
||||||
int size = (short) getNumber(data, offset, SHORT_SIZE);
|
int size = (short) getNumber(data, offset, SHORT_SIZE);
|
||||||
short[] results = new short[size];
|
short[] results = getSimpleShortArray(data, offset, size);
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
results[i] = getShort(data, offset + 2 + (i * 2));
|
|
||||||
}
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,5 +574,22 @@ public class LittleEndian
|
|||||||
{
|
{
|
||||||
return getUnsignedByte(data, 0);
|
return getUnsignedByte(data, 0);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Copy a portion of a byte array
|
||||||
|
*
|
||||||
|
* @param data the original byte array
|
||||||
|
* @param offset Where to start copying from.
|
||||||
|
* @param size Number of bytes to copy.
|
||||||
|
*
|
||||||
|
* @throws IndexOutOfBoundsException - if copying would cause access of data
|
||||||
|
* outside array bounds.
|
||||||
|
*/
|
||||||
|
public static byte[] getByteArray(final byte[] data, int offset, int size)
|
||||||
|
{
|
||||||
|
byte[] copy = new byte[size];
|
||||||
|
System.arraycopy(data, offset, copy, 0, size);
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user