use of io.fabric8.gateway.handlers.detecting.protocol.openwire.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);
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.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);
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.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);
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.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);
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.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);
}
}
Aggregations