Search in sources :

Example 1 with HopEofException

use of org.apache.hop.core.exception.HopEofException in project hop by apache.

the class ValueMetaAvroRecord method readData.

@Override
public Object readData(DataInputStream inputStream) throws HopFileException, SocketTimeoutException {
    try {
        // Is the value NULL?
        if (inputStream.readBoolean()) {
            // done
            return null;
        }
        // 
        if (schema == null) {
            throw new HopFileException("An Avro schema is needed to read a GenericRecord from an input stream");
        }
        BinaryDecoder binaryDecoder = DecoderFactory.get().directBinaryDecoder(inputStream, null);
        GenericDatumReader<GenericRecord> datumReader = new GenericDatumReader<>(schema);
        GenericRecord genericRecord = datumReader.read(null, binaryDecoder);
        return genericRecord;
    } catch (EOFException e) {
        throw new HopEofException(e);
    } catch (SocketTimeoutException e) {
        throw e;
    } catch (IOException e) {
        throw new HopFileException(toString() + " : Unable to read value data from input stream", e);
    }
}
Also used : HopFileException(org.apache.hop.core.exception.HopFileException) SocketTimeoutException(java.net.SocketTimeoutException) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) EOFException(java.io.EOFException) IOException(java.io.IOException) GenericRecord(org.apache.avro.generic.GenericRecord) HopEofException(org.apache.hop.core.exception.HopEofException)

Example 2 with HopEofException

use of org.apache.hop.core.exception.HopEofException in project hop by apache.

the class ValueMetaFactory method loadValueMeta.

public static IValueMeta loadValueMeta(DataInputStream inputStream) throws HopFileException {
    try {
        int type = inputStream.readInt();
        IValueMeta valueMeta = createValueMeta(type);
        valueMeta.readMetaData(inputStream);
        return valueMeta;
    } catch (EOFException e) {
        throw new HopEofException(e);
    } catch (Exception e) {
        throw new HopFileException("Unable to read value metadata from input stream", e);
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) HopFileException(org.apache.hop.core.exception.HopFileException) EOFException(java.io.EOFException) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopEofException(org.apache.hop.core.exception.HopEofException) EOFException(java.io.EOFException) HopFileException(org.apache.hop.core.exception.HopFileException) HopEofException(org.apache.hop.core.exception.HopEofException)

Example 3 with HopEofException

use of org.apache.hop.core.exception.HopEofException in project hop by apache.

the class ValueMetaTimestamp method readData.

@Override
public Object readData(DataInputStream inputStream) throws HopFileException, HopEofException, SocketTimeoutException {
    try {
        // Is the value NULL?
        if (inputStream.readBoolean()) {
            // done
            return null;
        }
        switch(storageType) {
            case STORAGE_TYPE_NORMAL:
                // Handle Content -- only when not NULL
                long time = inputStream.readLong();
                int nanos = inputStream.readInt();
                Timestamp timestamp = new Timestamp(time);
                timestamp.setNanos(nanos);
                return timestamp;
            case STORAGE_TYPE_BINARY_STRING:
                return readBinaryString(inputStream);
            case STORAGE_TYPE_INDEXED:
                // just an index: 4-bytes should be enough.
                return readSmallInteger(inputStream);
            default:
                throw new HopFileException(toString() + " : Unknown storage type " + getStorageType());
        }
    } catch (EOFException e) {
        throw new HopEofException(e);
    } catch (SocketTimeoutException e) {
        throw e;
    } catch (IOException e) {
        throw new HopFileException(toString() + " : Unable to read value timestamp data from input stream", e);
    }
}
Also used : HopFileException(org.apache.hop.core.exception.HopFileException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) IOException(java.io.IOException) HopEofException(org.apache.hop.core.exception.HopEofException)

Example 4 with HopEofException

use of org.apache.hop.core.exception.HopEofException in project hop by apache.

the class CubeInput method processRow.

@Override
public boolean processRow() throws HopException {
    if (first) {
        first = false;
        realRowLimit = Const.toInt(resolve(meta.getRowLimit()), 0);
    }
    try {
        Object[] r = data.meta.readData(data.dis);
        // fill the rowset(s). (sleeps if full)
        putRow(data.meta, r);
        incrementLinesInput();
        if (realRowLimit > 0 && getLinesInput() >= realRowLimit) {
            // finished!
            setOutputDone();
            return false;
        }
    } catch (HopEofException eof) {
        setOutputDone();
        return false;
    } catch (SocketTimeoutException e) {
        // shouldn't happen on files
        throw new HopException(e);
    }
    if (checkFeedback(getLinesInput())) {
        if (log.isBasic()) {
            logBasic(BaseMessages.getString(PKG, "CubeInput.Log.LineNumber") + getLinesInput());
        }
    }
    return true;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) HopException(org.apache.hop.core.exception.HopException) HopEofException(org.apache.hop.core.exception.HopEofException)

Aggregations

HopEofException (org.apache.hop.core.exception.HopEofException)4 EOFException (java.io.EOFException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 HopFileException (org.apache.hop.core.exception.HopFileException)3 IOException (java.io.IOException)2 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 HopException (org.apache.hop.core.exception.HopException)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 IValueMeta (org.apache.hop.core.row.IValueMeta)1