热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.poi.util.LittleEndian.getShort()方法的使用及代码示例

本文整理了Java中org.apache.poi.util.LittleEndian.getShort()方法的一些代码示例,展示了LittleEndian

本文整理了Java中org.apache.poi.util.LittleEndian.getShort()方法的一些代码示例,展示了LittleEndian.getShort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LittleEndian.getShort()方法的具体详情如下:
包路径:org.apache.poi.util.LittleEndian
类名称:LittleEndian
方法名:getShort

LittleEndian.getShort介绍

[英]get a short value from the beginning of a byte array
[中]从字节数组的开头获取短值

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
* get a short value from the beginning of a byte array
*
* @param data
* the byte array
* @return the short (16-bit) value
*/
public static short getShort( byte[] data )
{
return getShort( data, 0 );
}

代码示例来源:origin: org.apache.poi/poi

/**
* set the value from its offset into an array of bytes
*
* @param data the byte array from which the value is to be read
*
* @exception ArrayIndexOutOfBoundsException if the offset is out
* of range
*/
public void readFromBytes(final byte [] data)
throws ArrayIndexOutOfBoundsException
{
_value = LittleEndian.getShort(data, _offset);
}

代码示例来源:origin: org.apache.poi/poi

private short getShort(int offset) {
return LittleEndian.getShort( _rawData, offset);
}
private void setShort(int offset, int value) {

代码示例来源:origin: org.apache.poi/poi

/**
* Read short array
*
* @param data
* the original byte array
* @param offset
* Where to start copying from.
* @param size
* Number of bytes to copy.
* @throws IndexOutOfBoundsException
* - if read would cause access of data outside array bounds.
*/
public static short[] getShortArray( byte[] data, int offset, int size )
{
short[] result = new short[size / SHORT_SIZE];
for ( int i = 0; i {
result[i] = getShort( data, offset + i * SHORT_SIZE );
}
return result;
}

代码示例来源:origin: org.apache.poi/poi

/**
* Reads the 8 byte header information and populates the options
* and recordId records.
*
* @param data the byte array to read from
* @param offset the offset to start reading from
* @return the number of bytes remaining in this record. This
* may include the children if this is a container.
*/
protected int readHeader( byte[] data, int offset ) {
_optiOns= LittleEndian.getShort( data, offset );
_recordId = LittleEndian.getShort( data, offset + 2 );
return LittleEndian.getInt( data, offset + 4 );
}

代码示例来源:origin: org.apache.poi/poi

private void fillNextBuffer() throws IOException {
if (_innerHasReachedEOF) {
return;
}
int b0 = _is.read();
if (b0 == -1) {
_innerHasReachedEOF = true;
return;
}
_data[0] = (byte) b0;
_is.readFully(_data, 1, 3);
int len = LittleEndian.getShort(_data, 2);
_is.readFully(_data, 4, len);
_currentPos = 0;
_currentSize = len + 4;
_recordCounter++;
}
private void formatBufferIfAtEndOfRec() {

代码示例来源:origin: org.apache.poi/poi

field_1_flag = LittleEndian.getShort( data, pos + size ); size += 2;
field_2_col1 = LittleEndian.getShort( data, pos + size ); size += 2;
field_3_dx1 = LittleEndian.getShort( data, pos + size ); size += 2;
field_4_row1 = LittleEndian.getShort( data, pos + size ); size += 2;
if(bytesRemaining >= 18) {
field_5_dy1 = LittleEndian.getShort( data, pos + size ); size += 2;
field_6_col2 = LittleEndian.getShort( data, pos + size ); size += 2;
field_7_dx2 = LittleEndian.getShort( data, pos + size ); size += 2;
field_8_row2 = LittleEndian.getShort( data, pos + size ); size += 2;
field_9_dy2 = LittleEndian.getShort( data, pos + size ); size += 2;
shortRecord = false;
} else {

代码示例来源:origin: org.apache.poi/poi

private void formatBufferIfAtEndOfRec() {
if (_currentPos != _currentSize) {
return;
}
int dataSize = _currentSize-4;
int sid = LittleEndian.getShort(_data, 0);
int globalOffset = _overallStreamPos-_currentSize;
_listener.processRecord(globalOffset, _recordCounter, sid, dataSize, _data);
}
@Override

代码示例来源:origin: org.apache.poi/poi

/**
* Read the options field from header and return instance part of it.
* @param data the byte array to read from
* @param offset the offset to start reading from
* @return value of instance part of options field
*/
protected static short readInstance( byte data[], int offset ) {
final short optiOns= LittleEndian.getShort( data, offset );
return fInstance.getShortValue( options );
}

代码示例来源:origin: org.apache.poi/poi

public short getSizeOfElements() {
return (emptyComplexPart) ? 0 : LittleEndian.getShort( getComplexData(), 4 );
}

代码示例来源:origin: org.apache.poi/poi

@Override
public short readShort() {
if (shouldSkipEncryptionOnCurrentRecord) {
readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
return LittleEndian.getShort(buffer);
} else {
return ccis.readShort();
}
}

代码示例来源:origin: org.apache.poi/poi

@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
int pos = offset + 8;
int size = 0;
switch (bytesRemaining) {
case 16: // RectStruct
field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4;
field_2_dy1 = LittleEndian.getInt( data, pos + size );size+=4;
field_3_dx2 = LittleEndian.getInt( data, pos + size );size+=4;
field_4_dy2 = LittleEndian.getInt( data, pos + size );size+=4;
break;
case 8: // SmallRectStruct
field_1_dx1 = LittleEndian.getShort( data, pos + size );size+=2;
field_2_dy1 = LittleEndian.getShort( data, pos + size );size+=2;
field_3_dx2 = LittleEndian.getShort( data, pos + size );size+=2;
field_4_dy2 = LittleEndian.getShort( data, pos + size );size+=2;
break;
default:
throw new RuntimeException("Invalid EscherChildAnchorRecord - neither 8 nor 16 bytes.");
}

return 8 + size;
}

代码示例来源:origin: org.apache.poi/poi

@Override
public short readShort() {
final int size = LittleEndianConsts.SHORT_SIZE;
checkPosition(size);
short le = LittleEndian.getShort(buf, pos);
long skipped = super.skip(size);
assert skipped == size : "Buffer overrun";
return le;
}

代码示例来源:origin: org.apache.poi/poi

@Override
public short readShort() {
checkAvaliable(SHORT_SIZE);
byte[] data = new byte[SHORT_SIZE];
readFully(data, 0, SHORT_SIZE);
return LittleEndian.getShort(data);
}

代码示例来源:origin: org.apache.poi/poi

public ImageHeaderWMF(byte[] data, final int off) {
int offset = off;
int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key
if (key != APMHEADER_KEY) {
LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing");
handle = 0;
left = 0;
top = 0;
right = 200;
bottom = 200;
inch = Units.POINT_DPI; //default resolution is 72 dpi
reserved = 0;
return;
}
handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE;
left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE;
reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE;
checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE;
if (checksum != getChecksum()){
LOG.log(POILogger.WARN, "WMF checksum does not match the header data");
}
}

代码示例来源:origin: org.apache.poi/poi

/**
* @return the rotation, in degrees, that is applied to a shape.
*/
public int getRotationDegree(){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TRANSFORM__ROTATION);
if (null == property){
return 0;
}
try {
LittleEndian.putInt(property.getPropertyValue(), bos);
return LittleEndian.getShort(bos.toByteArray(), 2);
} catch (IOException e) {
LOG.log(POILogger.ERROR, "can't determine rotation degree", e);
return 0;
}
}

代码示例来源:origin: org.apache.poi/poi

/**
* We have this method because the way in which arrays in escher works
* is screwed for seemly arbitrary reasons. While most properties are
* fairly consistent and have a predictable array size, escher arrays
* have special cases.
*
* @param data The data array containing the escher array information
* @param offset The offset into the array to start reading from.
* @return the number of bytes used by this complex property.
*/
public int setArrayData(byte[] data, int offset) {
if (emptyComplexPart){
setComplexData(new byte[0]);
} else {
short numElements = LittleEndian.getShort(data, offset);
// LittleEndian.getShort(data, offset + 2); // numReserved
short sizeOfElements = LittleEndian.getShort(data, offset + 4);
// the code here seems to depend on complexData already being
// sized correctly via the constructor
int arraySize = getActualSizeOfElements(sizeOfElements) * numElements;
if (arraySize == getComplexData().length) {
// The stored data size in the simple block excludes the header size
setComplexData(new byte[arraySize + 6]);
sizeIncludesHeaderSize = false;
}
System.arraycopy(data, offset, getComplexData(), 0, getComplexData().length );
}
return getComplexData().length;
}

代码示例来源:origin: org.apache.poi/poi

/**
* @return array of x coordinates
*/
public int[] getXPoints() {
EscherArrayProperty verticesProp = getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
if (null == verticesProp){
return new int[]{};
}
int []array = new int[verticesProp.getNumberOfElementsInArray()-1];
for (int i=0; i byte[] property = verticesProp.getElement(i);
short x = LittleEndian.getShort(property, 0);
array[i] = x;
}
return array;
}

代码示例来源:origin: org.apache.poi/poi

/**
* @return array of y coordinates
*/
public int[] getYPoints() {
EscherArrayProperty verticesProp = getOptRecord().lookup(EscherProperties.GEOMETRY__VERTICES);
if (null == verticesProp){
return new int[]{};
}
int []array = new int[verticesProp.getNumberOfElementsInArray()-1];
for (int i=0; i byte[] property = verticesProp.getElement(i);
short x = LittleEndian.getShort(property, 2);
array[i] = x;
}
return array;
}

代码示例来源:origin: org.apache.poi/poi

@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
int pos = offset + 8;
field_1_blipTypeWin32 = data[pos];
field_2_blipTypeMacOS = data[pos + 1];
System.arraycopy( data, pos + 2, field_3_uid, 0, 16 );
field_4_tag = LittleEndian.getShort( data, pos + 18 );
field_5_size = LittleEndian.getInt( data, pos + 20 );
field_6_ref = LittleEndian.getInt( data, pos + 24 );
field_7_offset = LittleEndian.getInt( data, pos + 28 );
field_8_usage = data[pos + 32];
field_9_name = data[pos + 33];
field_10_unused2 = data[pos + 34];
field_11_unused3 = data[pos + 35];
bytesRemaining -= 36;
int bytesRead = 0;
if (bytesRemaining > 0) {
// Some older escher formats skip this last record
field_12_blipRecord = (EscherBlipRecord) recordFactory.createRecord( data, pos + 36 );
bytesRead = field_12_blipRecord.fillFields( data, pos + 36, recordFactory );
}
pos += 36 + bytesRead;
bytesRemaining -= bytesRead;
_remainingData = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, pos, _remainingData, 0, bytesRemaining );
return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize()) ;
}

推荐阅读
author-avatar
暖暖de苹果的马甲
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有