Top Description Fields Constructors Methods
org.apache.poi.hpsf

public Class VariantSupport

extends Variant
Class Inheritance
Imports
java.io.IOException, .OutputStream, .UnsupportedEncodingException, java.math.BigInteger, java.util.Date, .LinkedList, .List, org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.util.IOUtils, .LittleEndian, .LittleEndianByteArrayInputStream, .LittleEndianConsts

Supports reading and writing of variant data.

FIXME (3): Reading and writing should be made more uniform than it is now. The following items should be resolved:

Field Summary

Modifier and TypeField and Description
private static final Logger
private static boolean
private static final byte[]
public static final int[]
SUPPORTED_TYPES

HPSF is able to read these Variant types.

private static List<Long>
unsupportedMessage

Keeps a list of the variant types an "unsupported" message has already been issued for.

Inherited from org.apache.poi.hpsf.Variant:
LENGTH_0LENGTH_2LENGTH_4LENGTH_8LENGTH_UNKNOWNLENGTH_VARIABLEVT_ARRAYVT_BLOBVT_BLOB_OBJECTVT_BOOLVT_BSTRVT_BYREFVT_CARRAYVT_CFVT_CLSIDVT_CYVT_DATEVT_DECIMALVT_DISPATCHVT_EMPTYVT_ERRORVT_FILETIMEVT_HRESULTVT_I1VT_I2VT_I4VT_I8VT_ILLEGALVT_ILLEGALMASKEDVT_INTVT_LPSTRVT_LPWSTRVT_NULLVT_PTRVT_R4VT_R8VT_RESERVEDVT_SAFEARRAYVT_STORAGEVT_STORED_OBJECTVT_STREAMVT_STREAMED_OBJECTVT_TYPEMASKVT_UI1VT_UI2VT_UI4VT_UI8VT_UINTVT_UNKNOWNVT_USERDEFINEDVT_VARIANTVT_VECTORVT_VERSIONED_STREAMVT_VOID

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if logging is turned on, else false.
isLogUnsupportedTypes
()

Checks whether logging of unsupported variant types warning is turned on or off.

public boolean

Returns:

true if HPFS supports this type, else false
isSupportedType
(final int
the variant type to check
variantType
)

Checks whether HPSF supports the specified variant type.

public static Object

Returns:

A Java object that corresponds best to the variant field. For example, a VT_I4 is returned as a Long, a VT_LPSTR as a String.
read
(final byte[]
The byte array
src
,
final int
The offset in the byte array where the variant starts
offset
,
final int
The length of the variant including the variant type field
length
,
final long
The variant type to read
type
,
final int
The codepage to use for non-wide strings
codepage
)

Reads a variant type from a byte array.

public static Object
read(LittleEndianByteArrayInputStream lei, final int length, final long type, final int codepage)

public static void
setLogUnsupportedTypes(final boolean
If true warnings will be written, if false they won't.
logUnsupportedTypes
)

Specifies whether warnings about unsupported variant types are to be written to System.err or not.

public static int

Returns:

The number of entities that have been written. In many cases an "entity" is a byte but this is not always the case.
write
(final OutputStream
The stream to write the value to.
out
,
final long
The variant's type.
type
,
final Object
The variant's value.
value
,
final int
The codepage to use to write non-wide strings
codepage
)

Writes a variant value to an output stream.

protected static void
writeUnsupportedTypeMessage(final UnsupportedVariantTypeException
The exception to log
ex
)

Writes a warning to System.err that a variant type is unsupported by HPSF.

Inherited from org.apache.poi.hpsf.Variant:
getVariantLengthgetVariantName

Field Detail

LOGback to summary
private static final Logger LOG
logUnsupportedTypesback to summary
private static boolean logUnsupportedTypes
paddingBytesback to summary
private static final byte[] paddingBytes
SUPPORTED_TYPESback to summary
public static final int[] SUPPORTED_TYPES

HPSF is able to read these Variant types.

unsupportedMessageback to summary
private static List<Long> unsupportedMessage

Keeps a list of the variant types an "unsupported" message has already been issued for.

Constructor Detail

VariantSupportback to summary
public VariantSupport()

Method Detail

isLogUnsupportedTypesback to summary
public static boolean isLogUnsupportedTypes()

Checks whether logging of unsupported variant types warning is turned on or off.

Returns:boolean

true if logging is turned on, else false.

isSupportedTypeback to summary
public boolean isSupportedType(final int variantType)

Checks whether HPSF supports the specified variant type. Unsupported types should be implemented included in the SUPPORTED_TYPES array.

Parameters
variantType:int

the variant type to check

Returns:boolean

true if HPFS supports this type, else false

See Also
Variant
readback to summary
public static Object read(final byte[] src, final int offset, final int length, final long type, final int codepage) throws ReadingNotSupportedException, UnsupportedEncodingException

Reads a variant type from a byte array.

Parameters
src:byte[]

The byte array

offset:int

The offset in the byte array where the variant starts

length:int

The length of the variant including the variant type field

type:long

The variant type to read

codepage:int

The codepage to use for non-wide strings

Returns:Object

A Java object that corresponds best to the variant field. For example, a VT_I4 is returned as a Long, a VT_LPSTR as a String.

Exceptions
ReadingNotSupportedException:
if a property is to be written who's variant type HPSF does not yet support
UnsupportedEncodingException:
if the specified codepage is not supported.
See Also
Variant
readback to summary
public static Object read(LittleEndianByteArrayInputStream lei, final int length, final long type, final int codepage) throws ReadingNotSupportedException, UnsupportedEncodingException
setLogUnsupportedTypesback to summary
public static void setLogUnsupportedTypes(final boolean logUnsupportedTypes)

Specifies whether warnings about unsupported variant types are to be written to System.err or not.

Parameters
logUnsupportedTypes:boolean

If true warnings will be written, if false they won't.

writeback to summary
public static int write(final OutputStream out, final long type, final Object value, final int codepage) throws IOException, WritingNotSupportedException

Writes a variant value to an output stream. This method ensures that always a multiple of 4 bytes is written.

Parameters
out:OutputStream

The stream to write the value to.

type:long

The variant's type.

value:Object

The variant's value.

codepage:int

The codepage to use to write non-wide strings

Returns:int

The number of entities that have been written. In many cases an "entity" is a byte but this is not always the case.

Exceptions
IOException:
if an I/O exceptions occurs
WritingNotSupportedException:
if a property is to be written who's variant type HPSF does not yet support
writeUnsupportedTypeMessageback to summary
protected static void writeUnsupportedTypeMessage(final UnsupportedVariantTypeException ex)

Writes a warning to System.err that a variant type is unsupported by HPSF. Such a warning is written only once for each variant type. Log messages can be turned on or off by

Parameters
ex:UnsupportedVariantTypeException

The exception to log