Browse Source

replace exception with warning

update test case

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195053 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA5
Sergey Vladimirov 12 years ago
parent
commit
a3b1385736

+ 15
- 4
src/java/org/apache/poi/hpsf/ClipboardData.java View File

@@ -21,10 +21,15 @@ import java.io.OutputStream;

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;

@@ -33,9 +38,16 @@ class ClipboardData
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 );
@@ -57,7 +69,6 @@ class ClipboardData
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;

+ 3
- 10
src/testcases/org/apache/poi/hpsf/basic/TestWrite.java View File

@@ -36,7 +36,7 @@ import java.util.Map;

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;
@@ -63,7 +63,6 @@ import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
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>
@@ -377,14 +376,8 @@ public class TestWrite extends TestCase
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);

Loading…
Cancel
Save