Improvements to arg checking in constructor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@723141 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bff86351a1
commit
3a9e4eb667
@ -30,9 +30,17 @@ public final class LittleEndianByteArrayOutputStream implements LittleEndianOutp
|
|||||||
private int _writeIndex;
|
private int _writeIndex;
|
||||||
|
|
||||||
public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset, int maxWriteLen) {
|
public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset, int maxWriteLen) {
|
||||||
|
if (startOffset < 0 || startOffset > buf.length) {
|
||||||
|
throw new IllegalArgumentException("Specified startOffset (" + startOffset
|
||||||
|
+ ") is out of allowable range (0.." + buf.length + ")");
|
||||||
|
}
|
||||||
_buf = buf;
|
_buf = buf;
|
||||||
_writeIndex = startOffset;
|
_writeIndex = startOffset;
|
||||||
_endIndex = startOffset + maxWriteLen;
|
_endIndex = startOffset + maxWriteLen;
|
||||||
|
if (_endIndex < startOffset || _endIndex > buf.length) {
|
||||||
|
throw new IllegalArgumentException("calculated end index (" + _endIndex
|
||||||
|
+ ") is out of allowable range (" + _writeIndex + ".." + buf.length + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset) {
|
public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset) {
|
||||||
this(buf, startOffset, buf.length - startOffset);
|
this(buf, startOffset, buf.length - startOffset);
|
||||||
@ -91,7 +99,7 @@ public final class LittleEndianByteArrayOutputStream implements LittleEndianOutp
|
|||||||
}
|
}
|
||||||
public LittleEndianOutput createDelayedOutput(int size) {
|
public LittleEndianOutput createDelayedOutput(int size) {
|
||||||
checkPosition(size);
|
checkPosition(size);
|
||||||
LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, _writeIndex+size);
|
LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, size);
|
||||||
_writeIndex += size;
|
_writeIndex += size;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user