import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
@Internal
class ClipboardData
{
+ private static final POILogger logger = POILogFactory
+ .getLogger( ClipboardData.class );
+
private int _format;
private byte[] _value;
int size = LittleEndian.getInt( data, offset );
if ( size < 4 )
- throw new IllegalPropertySetDataException(
- "ClipboardData size less than 4 bytes "
- + "(doesn't even have format field!)" );
+ {
+ logger.log( POILogger.WARN, "ClipboardData at offset ",
+ Integer.valueOf( offset ), " size less than 4 bytes "
+ + "(doesn't even have format field!). "
+ + "Setting to format == 0 and hope for the best" );
+ _format = 0;
+ _value = new byte[0];
+ return;
+ }
+
_format = LittleEndian.getInt( data, offset + LittleEndian.INT_SIZE );
_value = LittleEndian.getByteArray( data, offset
+ LittleEndian.INT_SIZE * 2, size - LittleEndian.INT_SIZE );
LittleEndian.putInt( result, 0 * LittleEndian.INT_SIZE,
LittleEndian.INT_SIZE + _value.length );
LittleEndian.putInt( result, 1 * LittleEndian.INT_SIZE, _format );
- LittleEndian.putInt( result, 2 * LittleEndian.INT_SIZE, _value.length );
System.arraycopy( _value, 0, result, LittleEndian.INT_SIZE
+ LittleEndian.INT_SIZE, _value.length );
return result;
import junit.framework.Assert;
import junit.framework.TestCase;
-
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.hpsf.Constants;
import org.apache.poi.hpsf.HPSFRuntimeException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.TempFile;
-import org.apache.poi.POIDataSamples;
/**
* <p>Tests HPSF's writing functionality.</p>
check(Variant.VT_EMPTY, null, codepage);
check(Variant.VT_BOOL, Boolean.TRUE, codepage);
check(Variant.VT_BOOL, Boolean.FALSE, codepage);
- check(Variant.VT_CF, new byte[]{0}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1, 2}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1, 2, 3}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage);
- check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage);
+ check( Variant.VT_CF, new byte[] { 8, 0, 0, 0, 1, 0, 0, 0, 1, 2, 3,
+ 4 }, codepage );
check(Variant.VT_I4, Integer.valueOf(27), codepage);
check(Variant.VT_I8, Long.valueOf(28), codepage);
check(Variant.VT_R8, new Double(29.0), codepage);