Search in sources :

Example 11 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method readString.

public String readString() throws OpenwireException {
    initializeReading();
    try {
        this.dataIn.mark(65);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new OpenwireException("reached end of data");
        }
        if (type == MarshallingSupport.NULL) {
            return null;
        }
        if (type == MarshallingSupport.BIG_STRING_TYPE) {
            return MarshallingSupport.readUTF8(dataIn);
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return this.dataIn.readUTF();
        }
        if (type == MarshallingSupport.LONG_TYPE) {
            return new Long(this.dataIn.readLong()).toString();
        }
        if (type == MarshallingSupport.INTEGER_TYPE) {
            return new Integer(this.dataIn.readInt()).toString();
        }
        if (type == MarshallingSupport.SHORT_TYPE) {
            return new Short(this.dataIn.readShort()).toString();
        }
        if (type == MarshallingSupport.BYTE_TYPE) {
            return new Byte(this.dataIn.readByte()).toString();
        }
        if (type == MarshallingSupport.FLOAT_TYPE) {
            return new Float(this.dataIn.readFloat()).toString();
        }
        if (type == MarshallingSupport.DOUBLE_TYPE) {
            return new Double(this.dataIn.readDouble()).toString();
        }
        if (type == MarshallingSupport.BOOLEAN_TYPE) {
            return (this.dataIn.readBoolean() ? Boolean.TRUE : Boolean.FALSE).toString();
        }
        if (type == MarshallingSupport.CHAR_TYPE) {
            return new Character(this.dataIn.readChar()).toString();
        } else {
            this.dataIn.reset();
            throw new OpenwireException(" not a String type");
        }
    } catch (NumberFormatException mfe) {
        try {
            this.dataIn.reset();
        } catch (IOException ioe) {
            throw new OpenwireException(ioe);
        }
        throw mfe;
    } catch (EOFException e) {
        throw new OpenwireException(e);
    } catch (IOException e) {
        throw new OpenwireException(e);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)

Example 12 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method readBytes.

public int readBytes(byte[] value) throws OpenwireException {
    initializeReading();
    try {
        if (value == null) {
            throw new NullPointerException();
        }
        if (remainingBytes == -1) {
            this.dataIn.mark(value.length + 1);
            int type = this.dataIn.read();
            if (type == -1) {
                throw new OpenwireException("reached end of data");
            }
            if (type != MarshallingSupport.BYTE_ARRAY_TYPE) {
                throw new OpenwireException("Not a byte array");
            }
            remainingBytes = this.dataIn.readInt();
        } else if (remainingBytes == 0) {
            remainingBytes = -1;
            return -1;
        }
        if (value.length <= remainingBytes) {
            // small buffer
            remainingBytes -= value.length;
            this.dataIn.readFully(value);
            return value.length;
        } else {
            // big buffer
            int rc = this.dataIn.read(value, 0, remainingBytes);
            remainingBytes = 0;
            return rc;
        }
    } catch (EOFException e) {
        throw new OpenwireException(e.getMessage(), e);
    } catch (IOException e) {
        throw new OpenwireException(e.getMessage(), e);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)

Example 13 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method readFloat.

public float readFloat() throws OpenwireException {
    initializeReading();
    try {
        this.dataIn.mark(33);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new OpenwireException("reached end of data");
        }
        if (type == MarshallingSupport.FLOAT_TYPE) {
            return this.dataIn.readFloat();
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return Float.valueOf(this.dataIn.readUTF()).floatValue();
        }
        if (type == MarshallingSupport.NULL) {
            this.dataIn.reset();
            throw new NullPointerException("Cannot convert NULL value to float.");
        } else {
            this.dataIn.reset();
            throw new OpenwireException(" not a float type");
        }
    } catch (NumberFormatException mfe) {
        try {
            this.dataIn.reset();
        } catch (IOException ioe) {
            throw new OpenwireException(ioe);
        }
        throw mfe;
    } catch (EOFException e) {
        throw new OpenwireException(e);
    } catch (IOException e) {
        throw new OpenwireException(e);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)

Example 14 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method readObject.

public Object readObject() throws OpenwireException {
    initializeReading();
    try {
        this.dataIn.mark(65);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new OpenwireException("reached end of data");
        }
        if (type == MarshallingSupport.NULL) {
            return null;
        }
        if (type == MarshallingSupport.BIG_STRING_TYPE) {
            return MarshallingSupport.readUTF8(dataIn);
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return this.dataIn.readUTF();
        }
        if (type == MarshallingSupport.LONG_TYPE) {
            return Long.valueOf(this.dataIn.readLong());
        }
        if (type == MarshallingSupport.INTEGER_TYPE) {
            return Integer.valueOf(this.dataIn.readInt());
        }
        if (type == MarshallingSupport.SHORT_TYPE) {
            return Short.valueOf(this.dataIn.readShort());
        }
        if (type == MarshallingSupport.BYTE_TYPE) {
            return Byte.valueOf(this.dataIn.readByte());
        }
        if (type == MarshallingSupport.FLOAT_TYPE) {
            return new Float(this.dataIn.readFloat());
        }
        if (type == MarshallingSupport.DOUBLE_TYPE) {
            return new Double(this.dataIn.readDouble());
        }
        if (type == MarshallingSupport.BOOLEAN_TYPE) {
            return this.dataIn.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
        }
        if (type == MarshallingSupport.CHAR_TYPE) {
            return Character.valueOf(this.dataIn.readChar());
        }
        if (type == MarshallingSupport.BYTE_ARRAY_TYPE) {
            int len = this.dataIn.readInt();
            byte[] value = new byte[len];
            this.dataIn.readFully(value);
            return value;
        } else {
            this.dataIn.reset();
            throw new OpenwireException("unknown type");
        }
    } catch (NumberFormatException mfe) {
        try {
            this.dataIn.reset();
        } catch (IOException ioe) {
            throw new OpenwireException(ioe);
        }
        throw mfe;
    } catch (EOFException e) {
        throw new OpenwireException(e.getMessage(), e);
    } catch (IOException e) {
        throw new OpenwireException(e.getMessage(), e);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)

Example 15 with OpenwireException

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException in project fabric8 by jboss-fuse.

the class ActiveMQStreamMessage method readBoolean.

public boolean readBoolean() throws OpenwireException {
    initializeReading();
    try {
        this.dataIn.mark(10);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new OpenwireException("reached end of data");
        }
        if (type == MarshallingSupport.BOOLEAN_TYPE) {
            return this.dataIn.readBoolean();
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return Boolean.valueOf(this.dataIn.readUTF()).booleanValue();
        }
        if (type == MarshallingSupport.NULL) {
            this.dataIn.reset();
            throw new NullPointerException("Cannot convert NULL value to boolean.");
        } else {
            this.dataIn.reset();
            throw new OpenwireException(" not a boolean type");
        }
    } catch (EOFException e) {
        throw new OpenwireException(e);
    } catch (IOException e) {
        throw new OpenwireException(e);
    }
}
Also used : OpenwireException(io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)

Aggregations

OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)18 OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireException)3 InflaterInputStream (java.util.zip.InflaterInputStream)3 Buffer (org.fusesource.hawtbuf.Buffer)3 ByteArrayInputStream (org.fusesource.hawtbuf.ByteArrayInputStream)3 IOException (java.io.IOException)2 UTF8Buffer (org.fusesource.hawtbuf.UTF8Buffer)2 Constructor (java.lang.reflect.Constructor)1 URL (java.net.URL)1 Deflater (java.util.zip.Deflater)1 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)1 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)1