Author: kiwiwings
Date: Thu Apr 16 22:11:16 2020
New Revision: 1876640
URL: http://svn.apache.org/viewvc?rev=1876640&view=rev
Log:
Replace Allocate+System.arraycopy with Array.copyOf/Range and
IOUtils.safelyClone
Modified:
poi/trunk/src/java/org/apache/poi/ddf/EscherArrayProperty.java
poi/trunk/src/java/org/apache/poi/ddf/EscherBSERecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherBlipRecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherClientDataRecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherDgRecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
poi/trunk/src/java/org/apache/poi/ddf/EscherSpRecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherSpgrRecord.java
poi/trunk/src/java/org/apache/poi/ddf/EscherTextboxRecord.java
poi/trunk/src/java/org/apache/poi/ddf/UnknownEscherRecord.java
poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java
poi/trunk/src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java
poi/trunk/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java
poi/trunk/src/java/org/apache/poi/hssf/record/UserSViewBegin.java
poi/trunk/src/java/org/apache/poi/hssf/record/cont/ContinuableRecordInput.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
poi/trunk/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/Ole10Native.java
poi/trunk/src/java/org/apache/poi/poifs/property/Property.java
poi/trunk/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Mirr.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Npv.java
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumproduct.java
poi/trunk/src/java/org/apache/poi/util/ArrayUtil.java
poi/trunk/src/java/org/apache/poi/util/IOUtils.java
poi/trunk/src/java/org/apache/poi/util/LittleEndian.java
poi/trunk/src/java/org/apache/poi/util/StringUtil.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java
poi/trunk/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java
poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CString.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlinkAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjRefAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEmbeddedData.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtomLayout.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoContainer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
poi/trunk/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPieceTable.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/LVLFAbstractType.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/PICFAbstractType.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestObjRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentOutputStream.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDirectoryProperty.java
poi/trunk/src/testcases/org/apache/poi/poifs/property/TestDocumentProperty.java
poi/trunk/src/testcases/org/apache/poi/poifs/property/TestPropertyFactory.java
poi/trunk/src/testcases/org/apache/poi/poifs/property/TestRootProperty.java
poi/trunk/src/testcases/org/apache/poi/poifs/storage/TestHeaderBlockReading.java
poi/trunk/src/testcases/org/apache/poi/util/TestByteField.java
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherArrayProperty.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherArrayProperty.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherArrayProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherArrayProperty.java Thu Apr 16
22:11:16 2020
@@ -96,7 +96,7 @@ public final class EscherArrayProperty e
* @param propertyNumber the property number part of the property id
* @param isBlipId {@code true}, if it references a blip
* @param complexData the data
- *
+ *
* @deprecated use {@link #EscherArrayProperty(EscherPropertyTypes,
boolean, int)} and {@link #setComplexData(byte[])}
*/
@Deprecated
@@ -124,7 +124,7 @@ public final class EscherArrayProperty e
// when called by user code, fix the size to be valid for the header
return complexSize == 0 ? 6 : complexSize;
}
-
+
public int getNumberOfElementsInArray() {
return (emptyComplexPart) ? 0 :
LittleEndian.getUShort(getComplexData(), 0);
}
@@ -171,9 +171,7 @@ public final class EscherArrayProperty e
public byte[] getElement(int index) {
int actualSize = getActualSizeOfElements(getSizeOfElements());
- byte[] result = IOUtils.safelyAllocate(actualSize, MAX_RECORD_LENGTH);
- System.arraycopy(getComplexData(), FIXED_SIZE + index * actualSize,
result, 0, result.length );
- return result;
+ return IOUtils.safelyClone(getComplexData(), FIXED_SIZE + index *
actualSize, actualSize, MAX_RECORD_LENGTH);
}
public void setElement(int index, byte[] element) {
@@ -252,7 +250,7 @@ public final class EscherArrayProperty e
public boolean hasNext() {
return (idx < getNumberOfElementsInArray());
}
-
+
@Override
public byte[] next() {
if (!hasNext()) {
@@ -260,7 +258,7 @@ public final class EscherArrayProperty e
}
return getElement(idx++);
}
-
+
@Override
public void remove() {
throw new UnsupportedOperationException("not yet implemented");
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherBSERecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherBSERecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherBSERecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherBSERecord.java Thu Apr 16
22:11:16 2020
@@ -103,8 +103,8 @@ public final class EscherBSERecord exten
pos += 36 + bytesRead;
bytesRemaining -= bytesRead;
- _remainingData = IOUtils.safelyAllocate(bytesRemaining,
MAX_RECORD_LENGTH);
- System.arraycopy( data, pos, _remainingData, 0, bytesRemaining );
+ _remainingData = IOUtils.safelyClone(data, pos, bytesRemaining,
MAX_RECORD_LENGTH);
+
return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 :
field_12_blipRecord.getRecordSize()) ;
}
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherBlipRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherBlipRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherBlipRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherBlipRecord.java Thu Apr 16
22:11:16 2020
@@ -49,9 +49,7 @@ public class EscherBlipRecord extends Es
int bytesAfterHeader = readHeader( data, offset );
int pos = offset + HEADER_SIZE;
- field_pictureData = IOUtils.safelyAllocate(bytesAfterHeader,
MAX_RECORD_LENGTH);
- System.arraycopy(data, pos, field_pictureData, 0, bytesAfterHeader);
-
+ field_pictureData = IOUtils.safelyClone(data, pos, bytesAfterHeader,
MAX_RECORD_LENGTH);
return bytesAfterHeader + 8;
}
@@ -108,8 +106,7 @@ public class EscherBlipRecord extends Es
if (pictureData == null || offset < 0 || length < 0 ||
pictureData.length < offset+length) {
throw new IllegalArgumentException("picture data can't be null");
}
- field_pictureData = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
- System.arraycopy(pictureData, offset, field_pictureData, 0, length);
+ field_pictureData = IOUtils.safelyClone(pictureData, offset, length,
MAX_RECORD_LENGTH);
}
@Override
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java
(original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java Thu Apr
16 22:11:16 2020
@@ -106,8 +106,8 @@ public class EscherClientAnchorRecord ex
}
}
bytesRemaining -= size;
- remainingData = IOUtils.safelyAllocate(bytesRemaining,
MAX_RECORD_LENGTH);
- System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
+ remainingData = IOUtils.safelyClone(data, pos + size, bytesRemaining,
MAX_RECORD_LENGTH);
+
return 8 + size + bytesRemaining;
}
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherClientDataRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherClientDataRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherClientDataRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherClientDataRecord.java Thu Apr
16 22:11:16 2020
@@ -50,8 +50,9 @@ public class EscherClientDataRecord exte
public int fillFields(byte[] data, int offset, EscherRecordFactory
recordFactory) {
int bytesRemaining = readHeader( data, offset );
int pos = offset + 8;
- remainingData = (bytesRemaining == 0) ? EMPTY :
IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
- System.arraycopy( data, pos, remainingData, 0, bytesRemaining );
+
+ remainingData = (bytesRemaining == 0) ? EMPTY :
IOUtils.safelyClone(data, pos, bytesRemaining, MAX_RECORD_LENGTH);
+
return 8 + bytesRemaining;
}
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherDgRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherDgRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherDgRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherDgRecord.java Thu Apr 16
22:11:16 2020
@@ -45,14 +45,11 @@ public class EscherDgRecord extends Esch
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory
recordFactory) {
- /*int bytesRemaining =*/ readHeader( data, offset );
+ readHeader( data, offset );
int pos = offset + 8;
int size = 0;
field_1_numShapes = LittleEndian.getInt( data, pos + size );
size += 4;
field_2_lastMSOSPID = LittleEndian.getInt( data, pos + size );
size += 4;
-// bytesRemaining -= size;
-// remainingData = new byte[bytesRemaining];
-// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining
);
return getRecordSize();
}
@@ -66,8 +63,6 @@ public class EscherDgRecord extends Esch
LittleEndian.putInt( data, offset + 4, 8 );
LittleEndian.putInt( data, offset + 8, field_1_numShapes );
LittleEndian.putInt( data, offset + 12, field_2_lastMSOSPID );
-// System.arraycopy( remainingData, 0, data, offset + 26,
remainingData.length );
-// int pos = offset + 8 + 18 + remainingData.length;
listener.afterRecordSerialize( offset + 16, getRecordId(),
getRecordSize(), this );
return getRecordSize();
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherMetafileBlip.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherMetafileBlip.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherMetafileBlip.java Thu Apr 16
22:11:16 2020
@@ -106,8 +106,7 @@ public final class EscherMetafileBlip ex
field_6_fCompression = data[pos]; pos++;
field_7_fFilter = data[pos]; pos++;
- raw_pictureData = IOUtils.safelyAllocate(field_5_cbSave,
MAX_RECORD_LENGTH);
- System.arraycopy( data, pos, raw_pictureData, 0, field_5_cbSave );
+ raw_pictureData = IOUtils.safelyClone(data, pos, field_5_cbSave,
MAX_RECORD_LENGTH);
pos += field_5_cbSave;
// 0 means DEFLATE compression
@@ -120,8 +119,7 @@ public final class EscherMetafileBlip ex
int remaining = bytesAfterHeader - pos + offset + HEADER_SIZE;
if(remaining > 0) {
- remainingData = IOUtils.safelyAllocate(remaining,
MAX_RECORD_LENGTH);
- System.arraycopy( data, pos, remainingData, 0, remaining );
+ remainingData = IOUtils.safelyClone(data, pos, remaining,
MAX_RECORD_LENGTH);
}
return bytesAfterHeader + HEADER_SIZE;
}
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherSpRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherSpRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherSpRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherSpRecord.java Thu Apr 16
22:11:16 2020
@@ -88,14 +88,11 @@ public class EscherSpRecord extends Esch
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory
recordFactory) {
- /*int bytesRemaining =*/ readHeader( data, offset );
+ readHeader( data, offset );
int pos = offset + 8;
int size = 0;
field_1_shapeId = LittleEndian.getInt( data, pos + size );
size += 4;
field_2_flags = LittleEndian.getInt( data, pos + size );
size += 4;
-// bytesRemaining -= size;
-// remainingData = new byte[bytesRemaining];
-// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining
);
return getRecordSize();
}
@@ -119,8 +116,6 @@ public class EscherSpRecord extends Esch
LittleEndian.putInt( data, offset + 4, remainingBytes );
LittleEndian.putInt( data, offset + 8, field_1_shapeId );
LittleEndian.putInt( data, offset + 12, field_2_flags );
-// System.arraycopy( remainingData, 0, data, offset + 26,
remainingData.length );
-// int pos = offset + 8 + 18 + remainingData.length;
listener.afterRecordSerialize( offset + getRecordSize(),
getRecordId(), getRecordSize(), this );
return 8 + 8;
}
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherSpgrRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherSpgrRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherSpgrRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherSpgrRecord.java Thu Apr 16
22:11:16 2020
@@ -59,8 +59,6 @@ public class EscherSpgrRecord extends Es
if (bytesRemaining != 0) {
throw new RecordFormatException("Expected no remaining bytes but
got " + bytesRemaining);
}
-// remainingData = new byte[bytesRemaining];
-// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining
);
return 8 + size + bytesRemaining;
}
@@ -76,8 +74,6 @@ public class EscherSpgrRecord extends Es
LittleEndian.putInt( data, offset + 12, field_2_rectY1 );
LittleEndian.putInt( data, offset + 16, field_3_rectX2 );
LittleEndian.putInt( data, offset + 20, field_4_rectY2 );
-// System.arraycopy( remainingData, 0, data, offset + 26,
remainingData.length );
-// int pos = offset + 8 + 18 + remainingData.length;
listener.afterRecordSerialize( offset + getRecordSize(),
getRecordId(), offset + getRecordSize(), this );
return 8 + 16;
}
Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherTextboxRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherTextboxRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherTextboxRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherTextboxRecord.java Thu Apr 16
22:11:16 2020
@@ -54,10 +54,8 @@ public final class EscherTextboxRecord e
public int fillFields(byte[] data, int offset, EscherRecordFactory
recordFactory) {
int bytesRemaining = readHeader( data, offset );
- // Save the data, ready for the calling code to do something
- // useful with it
- thedata = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
- System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
+ // Save the data, ready for the calling code to do something useful
with it
+ thedata = IOUtils.safelyClone(data, offset + 8, bytesRemaining,
MAX_RECORD_LENGTH);
return bytesRemaining + 8;
}
@@ -103,10 +101,8 @@ public final class EscherTextboxRecord e
* @param start the start position in the buffer
* @param length the length of the block
*/
- public void setData(byte[] b, int start, int length)
- {
- thedata = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
- System.arraycopy(b,start,thedata,0,length);
+ public void setData(byte[] b, int start, int length) {
+ thedata = IOUtils.safelyClone(b, start, length, MAX_RECORD_LENGTH);
}
/**
Modified: poi/trunk/src/java/org/apache/poi/ddf/UnknownEscherRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/UnknownEscherRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/UnknownEscherRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/UnknownEscherRecord.java Thu Apr 16
22:11:16 2020
@@ -81,8 +81,8 @@ public final class UnknownEscherRecord e
bytesRemaining = 0;
}
- thedata = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
- System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
+ thedata = IOUtils.safelyClone(data, offset + 8, bytesRemaining,
MAX_RECORD_LENGTH);
+
return bytesRemaining + 8;
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java Thu Apr 16 22:11:16
2020
@@ -17,6 +17,7 @@
package org.apache.poi.hpsf;
+import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
/**
* <p>Class to manipulate data in the Clipboard Variant ({@link
@@ -119,6 +120,9 @@ public final class Thumbnail {
*/
public static final int CF_BITMAP = 2;
+ //arbitrarily selected; may need to increase
+ private static final int MAX_RECORD_LENGTH = 1_000_000;
+
/**
* <p>A <code>byte[]</code> to hold a thumbnail image in ({@link
* Variant#VT_CF VT_CF}) format.</p>
@@ -260,13 +264,6 @@ public final class Thumbnail {
"be CF_METAFILEPICT.");
}
byte[] thumbnail = getThumbnail();
- int wmfImageLength = thumbnail.length - OFFSET_WMFDATA;
- byte[] wmfImage = new byte[wmfImageLength];
- System.arraycopy(thumbnail,
- OFFSET_WMFDATA,
- wmfImage,
- 0,
- wmfImageLength);
- return wmfImage;
+ return IOUtils.safelyClone(thumbnail, OFFSET_WMFDATA, thumbnail.length
- OFFSET_WMFDATA, MAX_RECORD_LENGTH);
}
}
Modified:
poi/trunk/src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
---
poi/trunk/src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
(original)
+++
poi/trunk/src/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
Thu Apr 16 22:11:16 2020
@@ -87,17 +87,17 @@ public abstract class AbstractEscherHold
@Override
public int serialize(int offset, byte[] data)
{
- LittleEndian.putShort( data, 0 + offset, getSid() );
+ LittleEndian.putShort(data, offset, getSid() );
LittleEndian.putShort( data, 2 + offset, (short) ( getRecordSize() - 4
) );
byte[] rawData = getRawData();
if ( escherRecords.size() == 0 && rawData != null )
{
- LittleEndian.putShort(data, 0 + offset, getSid());
+ LittleEndian.putShort(data, offset, getSid());
LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() -
4));
System.arraycopy( rawData, 0, data, 4 + offset, rawData.length);
return rawData.length + 4;
}
- LittleEndian.putShort(data, 0 + offset, getSid());
+ LittleEndian.putShort(data, offset, getSid());
LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
int pos = offset + 4;
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FormatRecord.java Thu Apr 16
22:11:16 2020
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
+import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@@ -151,8 +152,7 @@ public final class FormatRecord extends
//there can be a remaining byte (without proper final '00')
//that should be read as a byte
if (ris.available() == 1) {
- char[] tmp = new char[buf.length+1];
- System.arraycopy(buf, 0, tmp, 0, buf.length);
+ char[] tmp = Arrays.copyOf(buf, buf.length+1);
tmp[buf.length] = (char)ris.readUByte();
buf = tmp;
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/HeaderFooterRecord.java Thu
Apr 16 22:11:16 2020
@@ -78,9 +78,7 @@ public final class HeaderFooterRecord ex
* @return the sheet view?s GUID
*/
public byte[] getGuid(){
- byte[] guid = new byte[16];
- System.arraycopy(_rawData, 12, guid, 0, guid.length);
- return guid;
+ return Arrays.copyOfRange(_rawData, 12, 12+16);
}
/**
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/UserSViewBegin.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/UserSViewBegin.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/UserSViewBegin.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/UserSViewBegin.java Thu Apr
16 22:11:16 2020
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
+import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@@ -74,9 +75,7 @@ public final class UserSViewBegin extend
* @return Globally unique identifier for the custom view
*/
public byte[] getGuid(){
- byte[] guid = new byte[16];
- System.arraycopy(_rawData, 0, guid, 0, guid.length);
- return guid;
+ return Arrays.copyOf(_rawData, 16);
}
@Override
Modified:
poi/trunk/src/java/org/apache/poi/hssf/record/cont/ContinuableRecordInput.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cont/ContinuableRecordInput.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
---
poi/trunk/src/java/org/apache/poi/hssf/record/cont/ContinuableRecordInput.java
(original)
+++
poi/trunk/src/java/org/apache/poi/hssf/record/cont/ContinuableRecordInput.java
Thu Apr 16 22:11:16 2020
@@ -19,8 +19,8 @@
package org.apache.poi.hssf.record.cont;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.ContinueRecord;
+import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LittleEndianInput;
/**
@@ -44,7 +44,7 @@ import org.apache.poi.util.LittleEndianI
*
* <p>
* YK: For now (March 2011) this class is only used to read
- * @see org.apache.poi.hssf.record.common.UnicodeString.ExtRst blocks of a
UnicodeString.
+ * @see org.apache.poi.hssf.record.common.ExtRst blocks of a UnicodeString.
*
* </p>
*/
@@ -78,7 +78,7 @@ public class ContinuableRecordInput impl
public int readUShort(){
int ch1 = readUByte();
int ch2 = readUByte();
- return (ch2 << 8) + (ch1 << 0);
+ return (ch2 << 8) + (ch1);
}
@Override
@@ -87,7 +87,7 @@ public class ContinuableRecordInput impl
int ch2 = _in.readUByte();
int ch3 = _in.readUByte();
int ch4 = _in.readUByte();
- return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0);
+ return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1);
}
@Override
@@ -107,7 +107,7 @@ public class ContinuableRecordInput impl
((long)b3 << 24) +
(b2 << 16) +
(b1 << 8) +
- (b0 << 0));
+ (b0));
}
@Override
@@ -124,7 +124,7 @@ public class ContinuableRecordInput impl
public void readFully(byte[] buf, int off, int len){
_in.readFully(buf, off, len);
}
-
+
@Override
public void readPlain(byte[] buf, int off, int len) {
readFully(buf, off, len);
Modified:
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
---
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
(original)
+++
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
Thu Apr 16 22:11:16 2020
@@ -96,7 +96,7 @@ public final class HSSFSheetConditionalF
* A factory method allowing the creation of conditional formatting
* rules using an Icon Set / Multi-State formatting.
* The thresholds for it will be created, but will be empty
- * and require configuring with
+ * and require configuring with
* {@link HSSFConditionalFormattingRule#getMultiStateFormatting()}
* then
* {@link HSSFIconMultiStateFormatting#getThresholds()}
@@ -109,12 +109,12 @@ public final class HSSFSheetConditionalF
/**
* Create a Databar conditional formatting rule.
- * <p>The thresholds and colour for it will be created, but will be
- * empty and require configuring with
+ * <p>The thresholds and colour for it will be created, but will be
+ * empty and require configuring with
* {@link HSSFConditionalFormattingRule#getDataBarFormatting()}
* then
* {@link HSSFDataBarFormatting#getMinThreshold()}
- * and
+ * and
* {@link HSSFDataBarFormatting#getMaxThreshold()}
*/
public HSSFConditionalFormattingRule
createConditionalFormattingRule(HSSFExtendedColor color) {
@@ -127,8 +127,8 @@ public final class HSSFSheetConditionalF
/**
* Create a Color Scale / Color Gradient conditional formatting rule.
- * <p>The thresholds and colours for it will be created, but will be
- * empty and require configuring with
+ * <p>The thresholds and colours for it will be created, but will be
+ * empty and require configuring with
* {@link HSSFConditionalFormattingRule#getColorScaleFormatting()}
* then
* {@link HSSFColorScaleFormatting#getThresholds()}
@@ -139,7 +139,7 @@ public final class HSSFSheetConditionalF
CFRule12Record rr = CFRule12Record.createColorScale(_sheet);
return new HSSFConditionalFormattingRule(_sheet, rr);
}
-
+
/**
* Adds a copy of HSSFConditionalFormatting object to the sheet
* <p>This method could be used to copy HSSFConditionalFormatting object
@@ -196,8 +196,9 @@ public final class HSSFSheetConditionalF
public int addConditionalFormatting(CellRangeAddress[] regions,
ConditionalFormattingRule[] cfRules) {
HSSFConditionalFormattingRule[] hfRules;
- if(cfRules instanceof HSSFConditionalFormattingRule[]) hfRules =
(HSSFConditionalFormattingRule[])cfRules;
- else {
+ if(cfRules instanceof HSSFConditionalFormattingRule[]) {
+ hfRules = (HSSFConditionalFormattingRule[])cfRules;
+ } else {
hfRules = new HSSFConditionalFormattingRule[cfRules.length];
System.arraycopy(cfRules, 0, hfRules, 0, hfRules.length);
}
@@ -206,7 +207,7 @@ public final class HSSFSheetConditionalF
public int addConditionalFormatting(CellRangeAddress[] regions,
HSSFConditionalFormattingRule rule1) {
- return addConditionalFormatting(regions, rule1 == null ?
+ return addConditionalFormatting(regions, rule1 == null ?
null : new HSSFConditionalFormattingRule[] { rule1 }
);
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Thu Apr
16 22:11:16 2020
@@ -23,7 +23,6 @@ import static org.apache.poi.hssf.model.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -93,10 +92,11 @@ import org.apache.poi.poifs.filesystem.D
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.EntryUtils;
+import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.FilteringDirectoryNode;
+import org.apache.poi.poifs.filesystem.Ole10Native;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.poifs.filesystem.Ole10Native;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.FormulaType;
@@ -133,6 +133,7 @@ public final class HSSFWorkbook extends
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
+ private static final int MAX_IMAGE_LENGTH = 50_000_000;
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
@@ -504,13 +505,13 @@ public final class HSSFWorkbook extends
workbook.updateNamesAfterCellShift(shifter);
updateNamedRangesAfterSheetReorder(oldSheetIndex, pos);
-
+
updateActiveSheetAfterSheetReorder(oldSheetIndex, pos);
}
-
+
/**
* copy-pasted from XSSFWorkbook#updateNamedRangesAfterSheetReorder(int,
int)
- *
+ *
* update sheet-scoped named ranges in this workbook after changing the
sheet order
* of a sheet at oldIndex to newIndex.
* Sheets between these indices will move left or right by 1.
@@ -540,7 +541,7 @@ public final class HSSFWorkbook extends
}
}
-
+
private void updateActiveSheetAfterSheetReorder(int oldIndex, int
newIndex) {
// adjust active sheet if necessary
int active = getActiveSheetIndex();
@@ -600,7 +601,7 @@ public final class HSSFWorkbook extends
}
setSelectedTabs(list);
}
-
+
/**
* Selects multiple sheets as a group. This is distinct from
* the 'active' sheet (which is the sheet with focus).
@@ -624,9 +625,9 @@ public final class HSSFWorkbook extends
short nSelected = (short) set.size();
workbook.getWindowOne().setNumSelectedTabs(nSelected);
}
-
+
/**
- * Gets the selected sheets (if more than one, Excel calls these a
[Group]).
+ * Gets the selected sheets (if more than one, Excel calls these a
[Group]).
*
* @return indices of selected sheets
*/
@@ -641,7 +642,7 @@ public final class HSSFWorkbook extends
}
return Collections.unmodifiableCollection(indexes);
}
-
+
/**
* Convenience method to set the active sheet. The active sheet is is the
sheet
* which is currently displayed when the workbook is viewed in Excel.
@@ -743,7 +744,7 @@ public final class HSSFWorkbook extends
validateSheetIndex(sheetIx);
return workbook.isSheetVeryHidden(sheetIx);
}
-
+
@Override
public SheetVisibility getSheetVisibility(int sheetIx) {
return workbook.getSheetVisibility(sheetIx);
@@ -945,7 +946,7 @@ public final class HSSFWorkbook extends
public Iterator<Sheet> iterator() {
return sheetIterator();
}
-
+
private final class SheetIterator<T extends Sheet> implements Iterator<T> {
final private Iterator<T> it;
private T cursor;
@@ -1294,7 +1295,7 @@ public final class HSSFWorkbook extends
* the Workbook was read, if any.
*
* <p>Once this has been called, no further
- * operations, updates or reads should be performed on the
+ * operations, updates or reads should be performed on the
* Workbook.
*/
@Override
@@ -1304,42 +1305,42 @@ public final class HSSFWorkbook extends
/**
* Write out this workbook to the currently open {@link File} via the
- * writeable {@link POIFSFileSystem} it was opened as.
- *
+ * writeable {@link POIFSFileSystem} it was opened as.
+ *
* <p>This will fail (with an {@link IllegalStateException} if the
* Workbook was opened read-only, opened from an {@link InputStream}
- * instead of a File, or if this is not the root document. For those
cases,
- * you must use {@link #write(OutputStream)} or {@link #write(File)} to
+ * instead of a File, or if this is not the root document. For those
cases,
+ * you must use {@link #write(OutputStream)} or {@link #write(File)} to
* write to a brand new document.
*/
@Override
public void write() throws IOException {
validateInPlaceWritePossible();
final DirectoryNode dir = getDirectory();
-
+
// Update the Workbook stream in the file
DocumentNode workbookNode = (DocumentNode)dir.getEntry(
getWorkbookDirEntryName(dir));
POIFSDocument workbookDoc = new POIFSDocument(workbookNode);
workbookDoc.replaceContents(new ByteArrayInputStream(getBytes()));
-
+
// Update the properties streams in the file
writeProperties();
-
+
// Sync with the File on disk
dir.getFileSystem().writeFilesystem();
}
-
+
/**
* Method write - write out this workbook to a new {@link File}. Constructs
* a new POI POIFSFileSystem, passes in the workbook binary representation
and
* writes it out. If the file exists, it will be replaced, otherwise a new
one
* will be created.
- *
+ *
* Note that you cannot write to the currently open File using this method.
* If you opened your Workbook from a File, you <i>must</i> use the {@link
#write()}
* method instead!
- *
+ *
* @param newFile The new File you wish to write the XLS to
*
* @exception IOException if anything can't be written.
@@ -1352,12 +1353,12 @@ public final class HSSFWorkbook extends
fs.writeFilesystem();
}
}
-
+
/**
* Method write - write out this workbook to an {@link OutputStream}.
Constructs
* a new POI POIFSFileSystem, passes in the workbook binary representation
and
* writes it out.
- *
+ *
* If {@code stream} is a {@link java.io.FileOutputStream} on a networked
drive
* or has a high cost/latency associated with each written byte,
* consider wrapping the OutputStream in a {@link
java.io.BufferedOutputStream}
@@ -1375,7 +1376,7 @@ public final class HSSFWorkbook extends
fs.writeFilesystem(stream);
}
}
-
+
/** Writes the workbook out to a brand new, empty POIFS */
private void write(POIFSFileSystem fs) throws IOException {
// For tracking what we've written out, used if we're
@@ -1387,7 +1388,7 @@ public final class HSSFWorkbook extends
// Write out our HPFS properties, if we have them
writeProperties(fs, excepts);
-
+
if (preserveNodes) {
// Don't write out the old Workbook, we'll be doing our new one
// If the file had an "incorrect" name for the workbook stream,
@@ -1457,7 +1458,7 @@ public final class HSSFWorkbook extends
if (log.check( POILogger.DEBUG )) {
log.log(DEBUG, "HSSFWorkbook.getBytes()");
}
-
+
HSSFSheet[] sheets = getSheets();
int nSheets = sheets.length;
@@ -1502,7 +1503,7 @@ public final class HSSFWorkbook extends
}
encryptBytes(retval);
-
+
return retval;
}
@@ -1555,7 +1556,7 @@ public final class HSSFWorkbook extends
throw new EncryptedDocumentException(e);
}
}
-
+
/*package*/ InternalWorkbook getWorkbook() {
return workbook;
}
@@ -1873,12 +1874,9 @@ public final class HSSFWorkbook extends
short escherTag;
switch (format) {
case PICTURE_TYPE_WMF:
- // remove first 22 bytes if file starts with magic bytes
D7-CD-C6-9A
- // see also
http://de.wikipedia.org/wiki/Windows_Metafile#Hinweise_zur_WMF-Spezifikation
- if (LittleEndian.getInt(pictureData) == 0x9AC6CDD7) {
- byte[] picDataNoHeader = new byte[pictureData.length - 22];
- System.arraycopy(pictureData, 22, picDataNoHeader, 0,
pictureData.length-22);
- pictureData = picDataNoHeader;
+ // remove first 22 bytes if file starts with the WMF placeable
header
+ if (FileMagic.valueOf(pictureData) == FileMagic.WMF) {
+ pictureData = IOUtils.safelyClone(pictureData, 22,
pictureData.length - 22, MAX_IMAGE_LENGTH);
}
// fall through
case PICTURE_TYPE_EMF:
@@ -2047,7 +2045,7 @@ public final class HSSFWorkbook extends
} while (oleDir == null);
Ole10Native.createOleMarkerEntry(oleDir);
-
+
Ole10Native oleNative = new Ole10Native(label, fileName, command,
oleData);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
oleNative.writeOut(bos);
@@ -2213,15 +2211,15 @@ public final class HSSFWorkbook extends
public boolean changeExternalReference(String oldUrl, String newUrl) {
return workbook.changeExternalReference(oldUrl, newUrl);
}
-
+
@Internal
public InternalWorkbook getInternalWorkbook() {
return workbook;
}
-
+
/**
* Returns the spreadsheet version (EXCLE97) of this workbook
- *
+ *
* @return EXCEL97 SpreadsheetVersion enum
* @since 3.14 beta 2
*/
Modified:
poi/trunk/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
---
poi/trunk/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
(original)
+++
poi/trunk/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java
Thu Apr 16 22:11:16 2020
@@ -135,8 +135,7 @@ public class BinaryRC4Decryptor extends
hashAlg.update(salt);
}
- hash = new byte[5];
- System.arraycopy(hashAlg.digest(), 0, hash, 0, 5);
+ hash = Arrays.copyOf(hashAlg.digest(), 5);
return new SecretKeySpec(hash, ver.getCipherAlgorithm().jceId);
}
Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/Ole10Native.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/Ole10Native.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/Ole10Native.java
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/Ole10Native.java Thu Apr
16 22:11:16 2020
@@ -43,12 +43,12 @@ public class Ole10Native {
/**
* Default content of the \u0001Ole entry
*/
- private static final byte[] OLE_MARKER_BYTES =
+ private static final byte[] OLE_MARKER_BYTES =
{ 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
private static final String OLE_MARKER_NAME = "\u0001Ole";
-
-
+
+
// (the fields as they appear in the raw record:)
private int totalSize; // 4 bytes, total size of record not
including this field
private short flags1 = 2; // 2 bytes, unknown, mostly [02 00]
@@ -59,10 +59,10 @@ public class Ole10Native {
private String command; // ASCIIZ, stored in this field without
the terminating zero
private byte[] dataBuffer; // varying size, the actual native data
private short flags3; // some final flags? or zero terminators?,
sometimes not there
-
+
/**
* the field encoding mode - merely a try-and-error guess ...
- **/
+ **/
private enum EncodingMode {
/**
* the data is stored in parsed format - including label, command, etc.
@@ -77,11 +77,11 @@ public class Ole10Native {
*/
compact
}
-
+
private EncodingMode mode;
-
-
+
+
/**
* Creates an instance of this class from an embedded OLE Object. The OLE
Object is expected
* to include a stream "{01}Ole10Native" which contains the
actual
@@ -95,7 +95,7 @@ public class Ole10Native {
public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem
poifs) throws IOException, Ole10NativeException {
return createFromEmbeddedOleObject(poifs.getRoot());
}
-
+
/**
* Creates an instance of this class from an embedded OLE Object. The OLE
Object is expected
* to include a stream "{01}Ole10Native" which contains the
actual
@@ -113,7 +113,7 @@ public class Ole10Native {
return new Ole10Native(data, 0);
}
}
-
+
/**
* Creates an instance and fills the fields based on ... the fields
*/
@@ -124,7 +124,7 @@ public class Ole10Native {
setDataBuffer(data);
mode = EncodingMode.parsed;
}
-
+
/**
* Creates an instance and fills the fields based on the data in the given
buffer.
*
@@ -134,14 +134,14 @@ public class Ole10Native {
*/
public Ole10Native(byte[] data, int offset) throws Ole10NativeException {
int ofs = offset; // current offset, initialized to start
-
+
if (data.length < offset + 2) {
throw new Ole10NativeException("data is too small");
}
-
+
totalSize = LittleEndian.getInt(data, ofs);
ofs += LittleEndianConsts.INT_SIZE;
-
+
mode = EncodingMode.unparsed;
if (LittleEndian.getShort(data, ofs) == 2) {
// some files like equations don't have a valid filename,
@@ -157,36 +157,36 @@ public class Ole10Native {
switch (mode) {
case parsed: {
flags1 = LittleEndian.getShort(data, ofs);
-
+
// structured format
ofs += LittleEndianConsts.SHORT_SIZE;
-
+
int len = getStringLength(data, ofs);
label = StringUtil.getFromCompressedUnicode(data, ofs, len - 1);
ofs += len;
-
+
len = getStringLength(data, ofs);
fileName = StringUtil.getFromCompressedUnicode(data, ofs, len - 1);
ofs += len;
-
+
flags2 = LittleEndian.getShort(data, ofs);
ofs += LittleEndianConsts.SHORT_SIZE;
-
+
unknown1 = LittleEndian.getShort(data, ofs);
ofs += LittleEndianConsts.SHORT_SIZE;
-
+
len = LittleEndian.getInt(data, ofs);
ofs += LittleEndianConsts.INT_SIZE;
command = StringUtil.getFromCompressedUnicode(data, ofs, len - 1);
ofs += len;
-
+
if (totalSize < ofs) {
throw new Ole10NativeException("Invalid Ole10Native");
}
-
+
dataSize = LittleEndian.getInt(data, ofs);
ofs += LittleEndianConsts.INT_SIZE;
-
+
if (dataSize < 0 || totalSize - (ofs -
LittleEndianConsts.INT_SIZE) < dataSize) {
throw new Ole10NativeException("Invalid Ole10Native");
}
@@ -206,14 +206,12 @@ public class Ole10Native {
if ((long)dataSize + (long)ofs > (long)data.length) { //cast to avoid
overflow
throw new Ole10NativeException("Invalid Ole10Native: declared data
length > available data");
}
- dataBuffer = IOUtils.safelyAllocate(dataSize, MAX_RECORD_LENGTH);
- System.arraycopy(data, ofs, dataBuffer, 0, dataSize);
- ofs += dataSize;
+ dataBuffer = IOUtils.safelyClone(data, ofs, dataSize,
MAX_RECORD_LENGTH);
}
/**
* Add the \1OLE marker entry, which is not the Ole10Native entry.
- * Beside this "\u0001Ole" record there were several other records, e.g.
CompObj,
+ * Beside this "\u0001Ole" record there were several other records, e.g.
CompObj,
* OlePresXXX, but it seems, that they aren't necessary
*/
public static void createOleMarkerEntry(final DirectoryEntry parent)
throws IOException {
@@ -224,14 +222,14 @@ public class Ole10Native {
/**
* Add the \1OLE marker entry, which is not the Ole10Native entry.
- * Beside this "\u0001Ole" record there were several other records, e.g.
CompObj,
+ * Beside this "\u0001Ole" record there were several other records, e.g.
CompObj,
* OlePresXXX, but it seems, that they aren't necessary
*/
public static void createOleMarkerEntry(final POIFSFileSystem poifs)
throws IOException {
createOleMarkerEntry(poifs.getRoot());
}
-
-
+
+
/*
* Helper - determine length of zero terminated string (ASCIIZ).
*/
@@ -247,7 +245,7 @@ public class Ole10Native {
/**
* Returns the value of the totalSize field - the total length of the
* structure is totalSize + 4 (value of this field + size of this field).
- *
+ *
* @return the totalSize
*/
public int getTotalSize() {
@@ -256,7 +254,7 @@ public class Ole10Native {
/**
* Returns flags1 - currently unknown - usually 0x0002.
- *
+ *
* @return the flags1
*/
public short getFlags1() {
@@ -267,7 +265,7 @@ public class Ole10Native {
* Returns the label field - usually the name of the file (without
* directory) but probably may be any name specified during
* packaging/embedding the data.
- *
+ *
* @return the label
*/
public String getLabel() {
@@ -277,7 +275,7 @@ public class Ole10Native {
/**
* Returns the fileName field - usually the name of the file being embedded
* including the full path.
- *
+ *
* @return the fileName
*/
public String getFileName() {
@@ -286,7 +284,7 @@ public class Ole10Native {
/**
* Returns flags2 - currently unknown - mostly 0x0000.
- *
+ *
* @return the flags2
*/
public short getFlags2() {
@@ -295,7 +293,7 @@ public class Ole10Native {
/**
* Returns unknown1 field - currently unknown.
- *
+ *
* @return the unknown1
*/
public short getUnknown1() {
@@ -306,7 +304,7 @@ public class Ole10Native {
* Returns the command field - usually the name of the file being embedded
* including the full path, may be a command specified during embedding the
* file.
- *
+ *
* @return the command
*/
public String getCommand() {
@@ -317,7 +315,7 @@ public class Ole10Native {
* Returns the size of the embedded file. If the size is 0 (zero), no data
* has been embedded. To be sure, that no data has been embedded, check
* whether {@link #getDataBuffer()} returns <code>null</code>.
- *
+ *
* @return the dataSize
*/
public int getDataSize() {
@@ -330,7 +328,7 @@ public class Ole10Native {
* provide information about the data, but the actual data is not included.
* (So label, filename etc. are available, but this method returns
* <code>null</code>.)
- *
+ *
* @return the dataBuffer
*/
public byte[] getDataBuffer() {
@@ -339,7 +337,7 @@ public class Ole10Native {
/**
* Returns the flags3 - currently unknown.
- *
+ *
* @return the flags3
*/
public short getFlags3() {
@@ -358,7 +356,7 @@ public class Ole10Native {
@SuppressWarnings("resource")
LittleEndianOutputStream leosOut = new LittleEndianOutputStream(out);
-
+
switch (mode) {
case parsed: {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -379,7 +377,7 @@ public class Ole10Native {
leos.write(getDataBuffer());
leos.writeShort(getFlags3());
leos.close(); // satisfy compiler ...
-
+
leosOut.writeInt(bos.size()); // total size
bos.writeTo(out);
break;
Modified: poi/trunk/src/java/org/apache/poi/poifs/property/Property.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/property/Property.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/property/Property.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/property/Property.java Thu Apr 16
22:11:16 2020
@@ -124,19 +124,13 @@ public abstract class Property implement
*/
protected Property(int index, byte [] array, int offset)
{
- _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ];
- System.arraycopy(array, offset, _raw_data, 0,
- POIFSConstants.PROPERTY_SIZE);
+ _raw_data = Arrays.copyOfRange(array, offset, offset +
POIFSConstants.PROPERTY_SIZE);
_name_size = new ShortField(_name_size_offset, _raw_data);
- _property_type =
- new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data);
+ _property_type = new
ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data);
_node_color = new ByteField(_node_color_offset, _raw_data);
- _previous_property = new IntegerField(_previous_property_offset,
- _raw_data);
- _next_property = new IntegerField(_next_property_offset,
- _raw_data);
- _child_property = new IntegerField(_child_property_offset,
- _raw_data);
+ _previous_property = new IntegerField(_previous_property_offset,
_raw_data);
+ _next_property = new IntegerField(_next_property_offset,
_raw_data);
+ _child_property = new IntegerField(_child_property_offset,
_raw_data);
_storage_clsid = new ClassID(_raw_data,_storage_clsid_offset);
_user_flags = new IntegerField(_user_flags_offset, 0,
_raw_data);
_seconds_1 = new IntegerField(_seconds_1_offset, _raw_data);
@@ -146,8 +140,7 @@ public abstract class Property implement
_start_block = new IntegerField(_start_block_offset, _raw_data);
_size = new IntegerField(_size_offset, _raw_data);
_index = index;
- int name_length = (_name_size.get() / LittleEndianConsts.SHORT_SIZE)
- - 1;
+ int name_length = (_name_size.get() / LittleEndianConsts.SHORT_SIZE) -
1;
if (name_length < 1)
{
Modified: poi/trunk/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
(original)
+++ poi/trunk/src/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java Thu
Apr 16 22:11:16 2020
@@ -245,8 +245,7 @@ public class EmbeddedExtractor implement
}
int pictureBytesLen = idxEnd-idxStart+6;
- byte[] pdfBytes = IOUtils.safelyAllocate(pictureBytesLen,
MAX_RECORD_LENGTH);
- System.arraycopy(pictureBytes, idxStart, pdfBytes, 0,
pictureBytesLen);
+ byte[] pdfBytes = IOUtils.safelyClone(pictureBytes, idxStart,
pictureBytesLen, MAX_RECORD_LENGTH);
String filename = source.getShapeName().trim();
if (!endsWithIgnoreCase(filename, ".pdf")) {
filename += ".pdf";
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Mirr.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Mirr.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Mirr.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Mirr.java Thu Apr 16
22:11:16 2020
@@ -18,6 +18,8 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Arrays;
+
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
@@ -60,8 +62,7 @@ public class Mirr extends MultiOperandNu
double financeRate = values[values.length-1];
double reinvestRate = values[values.length-2];
- double[] mirrValues = new double[values.length - 2];
- System.arraycopy(values, 0, mirrValues, 0, mirrValues.length);
+ double[] mirrValues = Arrays.copyOf(values, values.length - 2);
boolean mirrValuesAreAllNegatives = true;
for (double mirrValue : mirrValues) {
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
---
poi/trunk/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java
(original)
+++
poi/trunk/src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java
Thu Apr 16 22:11:16 2020
@@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Arrays;
+
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.ThreeDEval;
import org.apache.poi.ss.formula.TwoDEval;
@@ -67,20 +69,13 @@ public abstract class MultiOperandNumeri
}
public double[] toArray() {
- if (_count < 1) {
- return EMPTY_DOUBLE_ARRAY;
- }
- double[] result = new double[_count];
- System.arraycopy(_array, 0, result, 0, _count);
- return result;
+ return _count < 1 ? EMPTY_DOUBLE_ARRAY : Arrays.copyOf(_array,
_count);
}
private void ensureCapacity(int reqSize) {
if (reqSize > _array.length) {
int newSize = reqSize * 3 / 2; // grow with 50% extra
- double[] newArr = new double[newSize];
- System.arraycopy(_array, 0, newArr, 0, _count);
- _array = newArr;
+ _array = Arrays.copyOf(_array, newSize);
}
}
@@ -159,7 +154,7 @@ public abstract class MultiOperandNumeri
public boolean isHiddenRowCounted() {
return true;
}
-
+
/**
* Collects values from a single argument
*/
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Npv.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Npv.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Npv.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Npv.java Thu Apr 16
22:11:16 2020
@@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Arrays;
+
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
@@ -43,8 +45,7 @@ public final class Npv implements Functi
try {
double rate =
NumericFunction.singleOperandEvaluate(args[0], srcRowIndex, srcColumnIndex);
// convert tail arguments into an array of doubles
- ValueEval[] vargs = new ValueEval[args.length-1];
- System.arraycopy(args, 1, vargs, 0, vargs.length);
+ ValueEval[] vargs = Arrays.copyOfRange(args, 1, args.length,
ValueEval[].class);
double[] values =
AggregateFunction.ValueCollector.collectValues(vargs);
double result = FinanceLib.npv(rate, values);
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumproduct.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumproduct.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumproduct.java
(original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Sumproduct.java Thu
Apr 16 22:11:16 2020
@@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
+import java.util.Arrays;
+
import org.apache.poi.ss.formula.TwoDEval;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
@@ -124,9 +126,9 @@ public final class Sumproduct implements
private static ValueEval evaluateAreaSumProduct(ValueEval[] evalArgs)
throws EvaluationException {
int maxN = evalArgs.length;
- TwoDEval[] args = new TwoDEval[maxN];
+ TwoDEval[] args;
try {
- System.arraycopy(evalArgs, 0, args, 0, maxN);
+ args = Arrays.copyOf(evalArgs, maxN, TwoDEval[].class);
} catch (ArrayStoreException e) {
// one of the other args was not an AreaRef
return ErrorEval.VALUE_INVALID;
Modified: poi/trunk/src/java/org/apache/poi/util/ArrayUtil.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/ArrayUtil.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/ArrayUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/ArrayUtil.java Thu Apr 16 22:11:16
2020
@@ -18,6 +18,8 @@
package org.apache.poi.util;
+import java.util.Arrays;
+
/**
* Utility classes for dealing with arrays.
*/
@@ -54,8 +56,7 @@ public final class ArrayUtil {
}
// Grab the bit to move
- Object[] toMove = new Object[numToMove];
- System.arraycopy(array, moveFrom, toMove, 0, numToMove);
+ Object[] toMove = Arrays.copyOfRange(array, moveFrom,
moveFrom+numToMove);
// Grab the bit to be shifted
Object[] toShift;
@@ -63,14 +64,12 @@ public final class ArrayUtil {
if(moveFrom > moveTo) {
// Moving to an earlier point in the array
// Grab everything between the two points
- toShift = new Object[(moveFrom-moveTo)];
- System.arraycopy(array, moveTo, toShift, 0, toShift.length);
+ toShift = Arrays.copyOfRange(array, moveTo, moveFrom);
shiftTo = moveTo + numToMove;
} else {
// Moving to a later point in the array
// Grab everything from after the toMove block, to the new point
- toShift = new Object[(moveTo-moveFrom)];
- System.arraycopy(array, moveFrom+numToMove, toShift, 0,
toShift.length);
+ toShift = Arrays.copyOfRange(array, moveFrom+numToMove,
moveTo+numToMove);
shiftTo = moveFrom;
}
Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1876640&r1=1876639&r2=1876640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Thu Apr 16 22:11:16 2020
@@ -28,6 +28,7 @@ import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
+import java.util.Arrays;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
@@ -35,6 +36,8 @@ import org.apache.poi.EmptyFileException
import org.apache.poi.POIDocument;
import org.apache.poi.ss.usermodel.Workbook;
+
+@Internal
public final class IOUtils {
private static final POILogger logger = POILogFactory.getLogger(
IOUtils.class );
@@ -610,6 +613,18 @@ public final class IOUtils {
checkLength(length, maxLength);
}
+ public static byte[] safelyClone(byte[] src, int offset, int length, int
maxLength) {
+ if (src == null) {
+ return null;
+ }
+ assert(offset >= 0 && length >= 0 && maxLength >= 0);
+ safelyAllocateCheck(Math.min(src.length-offset,length), maxLength);
+ return Arrays.copyOfRange(src, offset, offset+length);
+ }
+
+
+
+
/**
* Simple utility function to check that you haven't hit EOF
* when reading a byte.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]