Search in sources :

Example 1 with BinaryComponentImpl

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);
    }
}
Also used : BinaryComponentImpl(org.vast.data.BinaryComponentImpl) AbstractDataComponentImpl(org.vast.data.AbstractDataComponentImpl) BinaryMember(net.opengis.swe.v20.BinaryMember) DataType(net.opengis.swe.v20.DataType)

Example 2 with BinaryComponentImpl

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);
    }
}
Also used : BinaryComponentImpl(org.vast.data.BinaryComponentImpl) DataType(net.opengis.swe.v20.DataType) ReaderException(org.vast.util.ReaderException)

Example 3 with BinaryComponentImpl

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);
    }
}
Also used : BinaryComponentImpl(org.vast.data.BinaryComponentImpl) DataBlock(net.opengis.swe.v20.DataBlock) CDMException(org.vast.cdm.common.CDMException) IOException(java.io.IOException) WriterException(org.vast.util.WriterException) DataType(net.opengis.swe.v20.DataType) WriterException(org.vast.util.WriterException)

Example 4 with BinaryComponentImpl

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;
}
Also used : DataComponent(net.opengis.swe.v20.DataComponent) BinaryComponentImpl(org.vast.data.BinaryComponentImpl) DataValue(org.vast.data.DataValue) ScalarIterator(org.vast.data.ScalarIterator) BinaryEncodingImpl(org.vast.data.BinaryEncodingImpl)

Example 5 with BinaryComponentImpl

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);
            }
        }
    }
}
Also used : DataComponent(net.opengis.swe.v20.DataComponent) CountImpl(org.vast.data.CountImpl) BinaryComponentImpl(org.vast.data.BinaryComponentImpl) AbstractDataComponentImpl(org.vast.data.AbstractDataComponentImpl) BinaryComponent(net.opengis.swe.v20.BinaryComponent) DataIterator(org.vast.data.DataIterator) BinaryMember(net.opengis.swe.v20.BinaryMember) DataArrayImpl(org.vast.data.DataArrayImpl)

Aggregations

BinaryComponentImpl (org.vast.data.BinaryComponentImpl)7 DataType (net.opengis.swe.v20.DataType)5 BinaryMember (net.opengis.swe.v20.BinaryMember)4 DataComponent (net.opengis.swe.v20.DataComponent)3 AbstractDataComponentImpl (org.vast.data.AbstractDataComponentImpl)3 CDMException (org.vast.cdm.common.CDMException)2 CountImpl (org.vast.data.CountImpl)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BinaryBlock (net.opengis.swe.v20.BinaryBlock)1 BinaryComponent (net.opengis.swe.v20.BinaryComponent)1 DataArray (net.opengis.swe.v20.DataArray)1 DataBlock (net.opengis.swe.v20.DataBlock)1 DataChoice (net.opengis.swe.v20.DataChoice)1 DataRecord (net.opengis.swe.v20.DataRecord)1 BinaryEncodingImpl (org.vast.data.BinaryEncodingImpl)1 BooleanImpl (org.vast.data.BooleanImpl)1 CategoryImpl (org.vast.data.CategoryImpl)1 DataArrayImpl (org.vast.data.DataArrayImpl)1 DataIterator (org.vast.data.DataIterator)1