allow SprmBuffer to append byte[] (public method)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145277 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a67574d250
commit
6769f34c5f
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.hwpf.sprm;
|
package org.apache.poi.hwpf.sprm;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
public final class SprmBuffer
|
public final class SprmBuffer
|
||||||
implements Cloneable
|
implements Cloneable
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ public final class SprmBuffer
|
|||||||
_offset = 0;
|
_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findSprm(short opcode)
|
public SprmOperation findSprm( short opcode )
|
||||||
{
|
{
|
||||||
int operation = SprmOperation.getOperationFromOpcode( opcode );
|
int operation = SprmOperation.getOperationFromOpcode( opcode );
|
||||||
int type = SprmOperation.getTypeFromOpcode( opcode );
|
int type = SprmOperation.getTypeFromOpcode( opcode );
|
||||||
@ -54,14 +54,23 @@ public final class SprmBuffer
|
|||||||
{
|
{
|
||||||
SprmOperation i = si.next();
|
SprmOperation i = si.next();
|
||||||
if ( i.getOperation() == operation && i.getType() == type )
|
if ( i.getOperation() == operation && i.getType() == type )
|
||||||
return i.getGrpprlOffset();
|
return i;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findSprmOffset( short opcode )
|
||||||
|
{
|
||||||
|
SprmOperation sprmOperation = findSprm( opcode );
|
||||||
|
if ( sprmOperation == null )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
return sprmOperation.getGrpprlOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateSprm(short opcode, byte operand)
|
public void updateSprm(short opcode, byte operand)
|
||||||
{
|
{
|
||||||
int grpprlOffset = findSprm(opcode);
|
int grpprlOffset = findSprmOffset(opcode);
|
||||||
if(grpprlOffset != -1)
|
if(grpprlOffset != -1)
|
||||||
{
|
{
|
||||||
_buf[grpprlOffset] = operand;
|
_buf[grpprlOffset] = operand;
|
||||||
@ -72,7 +81,7 @@ public final class SprmBuffer
|
|||||||
|
|
||||||
public void updateSprm(short opcode, short operand)
|
public void updateSprm(short opcode, short operand)
|
||||||
{
|
{
|
||||||
int grpprlOffset = findSprm(opcode);
|
int grpprlOffset = findSprmOffset(opcode);
|
||||||
if(grpprlOffset != -1)
|
if(grpprlOffset != -1)
|
||||||
{
|
{
|
||||||
LittleEndian.putShort(_buf, grpprlOffset, operand);
|
LittleEndian.putShort(_buf, grpprlOffset, operand);
|
||||||
@ -83,7 +92,7 @@ public final class SprmBuffer
|
|||||||
|
|
||||||
public void updateSprm(short opcode, int operand)
|
public void updateSprm(short opcode, int operand)
|
||||||
{
|
{
|
||||||
int grpprlOffset = findSprm(opcode);
|
int grpprlOffset = findSprmOffset(opcode);
|
||||||
if(grpprlOffset != -1)
|
if(grpprlOffset != -1)
|
||||||
{
|
{
|
||||||
LittleEndian.putInt(_buf, grpprlOffset, operand);
|
LittleEndian.putInt(_buf, grpprlOffset, operand);
|
||||||
@ -141,8 +150,14 @@ public final class SprmBuffer
|
|||||||
|
|
||||||
public void append( byte[] grpprl )
|
public void append( byte[] grpprl )
|
||||||
{
|
{
|
||||||
ensureCapacity(grpprl.length);
|
append( grpprl, 0 );
|
||||||
System.arraycopy(grpprl, 0, _buf, _offset, grpprl.length);
|
}
|
||||||
|
|
||||||
|
public void append( byte[] grpprl, int offset )
|
||||||
|
{
|
||||||
|
ensureCapacity( grpprl.length - offset );
|
||||||
|
System.arraycopy( grpprl, offset, _buf, _offset, grpprl.length - offset );
|
||||||
|
_offset += grpprl.length - offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
public Object clone()
|
||||||
@ -159,7 +174,11 @@ public final class SprmBuffer
|
|||||||
if ( _offset + addition >= _buf.length )
|
if ( _offset + addition >= _buf.length )
|
||||||
{
|
{
|
||||||
// add 6 more than they need for use the next iteration
|
// add 6 more than they need for use the next iteration
|
||||||
byte[] newBuf = new byte[_offset + addition + 6];
|
//
|
||||||
|
// commented - buffer shall not contain any additional bytes --
|
||||||
|
// sergey
|
||||||
|
// byte[] newBuf = new byte[_offset + addition + 6];
|
||||||
|
byte[] newBuf = new byte[_offset + addition];
|
||||||
System.arraycopy( _buf, 0, newBuf, 0, _buf.length );
|
System.arraycopy( _buf, 0, newBuf, 0, _buf.length );
|
||||||
_buf = newBuf;
|
_buf = newBuf;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user