org.apache.poi.hpbf.model.qcbits.QCPLCBit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apache-poi-ooxml Show documentation
Show all versions of apache-poi-ooxml Show documentation
The Apache Commons Codec package contains simple encoder and decoders for
various formats such as Base64 and Hexadecimal. In addition to these
widely used encoders and decoders, the codec package also maintains a
collection of phonetic encoding utilities.
The newest version!
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hpbf.model.qcbits;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
/**
* A "PLC " (PLC) based bit of Quill Contents. The exact
* format is determined by the type of the PLCs.
*/
public abstract class QCPLCBit extends QCBit {
private int numberOfPLCs;
private int typeOfPLCS;
/**
* The data which goes before the main PLC entries.
* This is apparently always made up of 2 byte
* un-signed ints..
*/
private int[] preData;
/** The first value of each PLC, normally 4 bytes */
private long[] plcValA;
/** The second value of each PLC, normally 4 bytes */
private long[] plcValB;
private QCPLCBit(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
// First four bytes are the number
numberOfPLCs = (int)LittleEndian.getUInt(data, 0);
// Next four bytes are the type
typeOfPLCS = (int)LittleEndian.getUInt(data, 4);
// Init the arrays that we can
plcValA = new long[numberOfPLCs];
plcValB = new long[numberOfPLCs];
}
public int getNumberOfPLCs() {
return numberOfPLCs;
}
public int getTypeOfPLCS() {
return typeOfPLCS;
}
public int[] getPreData() {
return preData;
}
public long[] getPlcValA() {
return plcValA;
}
public long[] getPlcValB() {
return plcValB;
}
final void setPreData(int[] preData) {
this.preData = preData.clone();
}
final void setPlcValA(long[] plcValA) {
this.plcValA = plcValA.clone();
}
final void setPlcValB(long[] plcValB) {
this.plcValB = plcValB.clone();
}
public static QCPLCBit createQCPLCBit(String thingType, String bitType, byte[] data) {
// Grab the type
int type = (int)LittleEndian.getUInt(data, 4);
switch(type) {
case 0:
return new Type0(thingType, bitType, data);
case 4:
return new Type4(thingType, bitType, data);
case 8:
return new Type8(thingType, bitType, data);
case 12: // 0xc
return new Type12(thingType, bitType, data);
default:
throw new IllegalArgumentException("Sorry, I don't know how to deal with PLCs of type " + type);
}
}
/**
* Type 0 seem to be somewhat rare. They have 8 bytes of pre-data,
* then 2x 2 byte values.
*/
public static class Type0 extends QCPLCBit {
private Type0(String thingType, String bitType, byte[] data) {
super(thingType, bitType, data);
// Grab our 4x pre-data
int[] preData = {
LittleEndian.getUShort(data, 8 + 0),
LittleEndian.getUShort(data, 8 + 2),
LittleEndian.getUShort(data, 8 + 4),
LittleEndian.getUShort(data, 8 + 6)
};
setPreData(preData);
// And grab the 2 byte values
int cntPlcs = getNumberOfPLCs();
long[] plcValA = new long[cntPlcs];
long[] plcValB = new long[cntPlcs];
for(int i=0; i= 2) {
until = twoStartsAt + (cntPlcs-2)*threePlusIncrement;
}
long[] plcValA = new long[(until - at) / 2];
long[] plcValB = new long[0];
for(int i=0; i