use of org.vast.data.BinaryComponentImpl in project lib-ogc by sensiasoft.
the class BinaryDataWriter method getAtomWriter.
protected BaseProcessor getAtomWriter(ScalarComponent component) {
BinaryMember enc = ((AbstractDataComponentImpl) component).getEncodingInfo();
DataType dataType = ((BinaryComponentImpl) enc).getCdmDataType();
switch(dataType) {
case BOOLEAN:
return new BooleanWriter();
case BYTE:
return new ByteWriter();
case UBYTE:
return new UByteWriter();
case SHORT:
return new ShortWriter();
case USHORT:
return new UShortWriter();
case INT:
return new IntWriter();
case UINT:
return new UIntWriter();
case LONG:
return new LongWriter();
case ULONG:
return new ULongWriter();
case FLOAT:
return new FloatWriter();
case DOUBLE:
return new DoubleWriter();
case UTF_STRING:
return new StringWriterUTF();
case ASCII_STRING:
return new StringWriterASCII();
default:
throw new IllegalStateException("Unsupported datatype " + dataType);
}
}
use of org.vast.data.BinaryComponentImpl in project lib-ogc by sensiasoft.
the class BinaryDataParser method parseBinaryAtom.
/**
* Parse binary block using DataInfo and DataEncoding structures
* Decoded value is assigned to each DataValue
* @param scalarInfo
* @param binaryInfo
* @throws IOException
*/
private void parseBinaryAtom(ScalarComponent scalarInfo, BinaryMember binaryInfo) throws IOException {
DataType dataType = ((BinaryComponentImpl) binaryInfo).getCdmDataType();
try {
switch(dataType) {
case BOOLEAN:
boolean boolValue = dataInput.readBoolean();
scalarInfo.getData().setBooleanValue(boolValue);
break;
case BYTE:
byte byteValue = dataInput.readByte();
scalarInfo.getData().setByteValue(byteValue);
break;
case UBYTE:
int ubyteValue = dataInput.readUnsignedByte();
scalarInfo.getData().setIntValue(ubyteValue);
break;
case SHORT:
short shortValue = dataInput.readShort();
scalarInfo.getData().setShortValue(shortValue);
break;
case USHORT:
int ushortValue = dataInput.readUnsignedShort();
scalarInfo.getData().setIntValue(ushortValue);
break;
case INT:
int intValue = dataInput.readInt();
scalarInfo.getData().setIntValue(intValue);
break;
case UINT:
long uintValue = dataInput.readUnsignedInt();
scalarInfo.getData().setLongValue(uintValue);
break;
case LONG:
long longValue = dataInput.readLong();
scalarInfo.getData().setLongValue(longValue);
break;
case ULONG:
long ulongValue = dataInput.readUnsignedLong();
scalarInfo.getData().setLongValue(ulongValue);
break;
case FLOAT:
float floatValue = dataInput.readFloat();
scalarInfo.getData().setFloatValue(floatValue);
break;
case DOUBLE:
double doubleValue = dataInput.readDouble();
scalarInfo.getData().setDoubleValue(doubleValue);
break;
case UTF_STRING:
String utfValue = dataInput.readUTF();
scalarInfo.getData().setStringValue(utfValue);
break;
case ASCII_STRING:
String asciiValue = dataInput.readASCII();
scalarInfo.getData().setStringValue(asciiValue);
break;
default:
throw new ReaderException("Unsupported datatype " + dataType);
}
} catch (RuntimeException e) {
throw new ReaderException("Error while parsing component " + scalarInfo.getName(), e);
}
}
use of org.vast.data.BinaryComponentImpl in project lib-ogc by sensiasoft.
the class BinaryDataWriter method writeBinaryAtom.
/**
* Parse binary component using info and encoding options
* Decoded value is assigned to each DataValue
* @param component
* @param binaryInfo
* @throws WriterException
*/
private void writeBinaryAtom(ScalarComponent component, BinaryMember binaryInfo) throws WriterException {
DataType dataType = ((BinaryComponentImpl) binaryInfo).getCdmDataType();
DataBlock data = component.getData();
try {
switch(dataType) {
case BOOLEAN:
boolean boolValue = data.getBooleanValue();
dataOutput.writeBoolean(boolValue);
break;
case BYTE:
byte byteValue = data.getByteValue();
dataOutput.writeByte(byteValue);
break;
case UBYTE:
short ubyteValue = data.getShortValue();
dataOutput.writeUnsignedByte(ubyteValue);
break;
case SHORT:
short shortValue = data.getShortValue();
dataOutput.writeShort(shortValue);
break;
case USHORT:
int ushortValue = data.getIntValue();
dataOutput.writeUnsignedShort(ushortValue);
break;
case INT:
int intValue = data.getIntValue();
dataOutput.writeInt(intValue);
break;
case UINT:
long uintValue = data.getLongValue();
dataOutput.writeUnsignedInt(uintValue);
break;
case LONG:
long longValue = data.getLongValue();
dataOutput.writeLong(longValue);
break;
case ULONG:
long ulongValue = data.getLongValue();
dataOutput.writeLong(ulongValue);
break;
case FLOAT:
float floatValue = data.getFloatValue();
dataOutput.writeFloat(floatValue);
break;
case DOUBLE:
double doubleValue = data.getDoubleValue();
dataOutput.writeDouble(doubleValue);
break;
case UTF_STRING:
String utfValue = data.getStringValue();
dataOutput.writeUTF(utfValue);
break;
case ASCII_STRING:
String asciiValue = data.getStringValue();
dataOutput.writeASCII(asciiValue);
break;
default:
throw new IllegalStateException("Unsupported datatype " + dataType);
}
} catch (Exception e) {
throw new WriterException("Error while writing scalar component " + component.getName(), e);
}
}
use of org.vast.data.BinaryComponentImpl in project lib-ogc by sensiasoft.
the class SWEHelper method getDefaultBinaryEncoding.
/**
* Get default binary encoding for the given component tree.<br/>
* Data types used will be ones specified in each scalar component.
* @param dataComponents component whose children will be mapped to encoding options
* @return binary encoding instance pre-configured for the component
*/
public static BinaryEncoding getDefaultBinaryEncoding(DataComponent dataComponents) {
BinaryEncodingImpl encoding = new BinaryEncodingImpl();
encoding.setByteEncoding(ByteEncoding.RAW);
encoding.setByteOrder(ByteOrder.BIG_ENDIAN);
// use default encoding info for each data value
ScalarIterator it = new ScalarIterator(dataComponents);
while (it.hasNext()) {
DataComponent[] nextPath = it.nextPath();
DataValue nextScalar = (DataValue) nextPath[nextPath.length - 1];
// build path (just use / for root)
StringBuilder pathString = new StringBuilder();
pathString.append(PATH_SEPARATOR);
for (int i = 0; i < nextPath.length; i++) {
pathString.append(nextPath[i].getName());
pathString.append(PATH_SEPARATOR);
}
BinaryComponentImpl binaryOpts = new BinaryComponentImpl();
binaryOpts.setCdmDataType(nextScalar.getDataType());
binaryOpts.setRef(pathString.substring(0, pathString.length() - 1));
encoding.addMemberAsComponent(binaryOpts);
nextScalar.setEncodingInfo(binaryOpts);
}
return encoding;
}
use of org.vast.data.BinaryComponentImpl in project lib-ogc by sensiasoft.
the class SWEHelper method assignBinaryEncoding.
/**
* Assigns binary components and blocks definitions to the actual data component.
* This sets the encodingInfo attribute of the component so it can be used to generate specialized datablocks.
* For scalars, it also sets the default data type so it is the same as in the encoded stream.
* @param dataComponents
* @param encoding
* @throws CDMException
*/
public static void assignBinaryEncoding(DataComponent dataComponents, BinaryEncoding encoding) throws CDMException {
for (BinaryMember binaryOpts : encoding.getMemberList()) {
DataComponent comp = findComponentByPath(dataComponents, binaryOpts.getRef());
((AbstractDataComponentImpl) comp).setEncodingInfo(binaryOpts);
// for scalars, also set default data type
if (binaryOpts instanceof BinaryComponent)
((AbstractSimpleComponentImpl) comp).setDataType(((BinaryComponentImpl) binaryOpts).getCdmDataType());
}
// set default data type for implicit array size components if not already set
DataIterator it = new DataIterator(dataComponents);
while (it.hasNext()) {
DataComponent comp = it.next();
if (comp instanceof DataArrayImpl) {
CountImpl count = (CountImpl) ((DataArrayImpl) comp).getArraySizeComponent();
if (count != null && count.getEncodingInfo() == null) {
BinaryComponent binaryOpts = new BinaryComponentImpl();
binaryOpts.setCdmDataType(count.getDataType());
count.setEncodingInfo(binaryOpts);
}
}
}
}
Aggregations