All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.poi.hpbf.model.qcbits.QCPLCBit Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show 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 {
	protected int numberOfPLCs;
	protected int typeOfPLCS;
	/**
	 * The data which goes before the main PLC entries.
	 * This is apparently always made up of 2 byte
	 *  un-signed ints..
	 */
	protected int[] preData;
	/** The first value of each PLC, normally 4 bytes */
	protected long[] plcValA;
	/** The second value of each PLC, normally 4 bytes */
	protected 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;
	}



	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
			preData = new int[4];
			preData[0] = LittleEndian.getUShort(data, 8+0);
			preData[1] = LittleEndian.getUShort(data, 8+2);
			preData[2] = LittleEndian.getUShort(data, 8+4);
			preData[3] = LittleEndian.getUShort(data, 8+6);

			// And grab the 2 byte values
			for(int i=0; i= 2) {
				until = twoStartsAt + (numberOfPLCs-2)*threePlusIncrement;
			}

			plcValA = new long[(until-at)/2];
			plcValB = new long[0];
			for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy