use of org.apache.activemq.util.ByteArrayInputStream in project timbuctoo by HuygensING.
the class HttpCallerTest method response.
private HttpResponse response(final int status, String value) throws IOException {
HttpResponse httpResponse = mock(HttpResponse.class);
when(httpResponse.getStatusLine()).thenReturn(new StatusLine() {
@Override
public ProtocolVersion getProtocolVersion() {
return new ProtocolVersion("http", 1, 1);
}
@Override
public int getStatusCode() {
return status;
}
@Override
public String getReasonPhrase() {
return "";
}
});
when(httpResponse.getAllHeaders()).thenReturn(new Header[] {});
HttpEntity entity = mock(HttpEntity.class);
when(entity.getContent()).thenReturn(new ByteArrayInputStream(value.getBytes()));
when(httpResponse.getEntity()).thenReturn(entity);
return httpResponse;
}
use of org.apache.activemq.util.ByteArrayInputStream in project activemq-artemis by apache.
the class OpenWireMessageConverter method writeCompressedObjectType.
private static ByteSequence writeCompressedObjectType(final ByteSequence contents) throws IOException {
try (InputStream ois = new InflaterInputStream(new ByteArrayInputStream(contents));
org.apache.activemq.util.ByteArrayOutputStream decompressed = new org.apache.activemq.util.ByteArrayOutputStream()) {
byte[] buf = new byte[1024];
int n = ois.read(buf);
while (n != -1) {
decompressed.write(buf, 0, n);
n = ois.read();
}
// read done
return decompressed.toByteSequence();
}
}
use of org.apache.activemq.util.ByteArrayInputStream in project activemq-artemis by apache.
the class OpenWireMessageConverter method writeMapType.
private static void writeMapType(final ByteSequence contents, final boolean messageCompressed, final ActiveMQBuffer body) throws IOException {
InputStream mis = new ByteArrayInputStream(contents);
if (messageCompressed) {
mis = new InflaterInputStream(mis);
}
DataInputStream mdataIn = new DataInputStream(mis);
Map<String, Object> map = MarshallingSupport.unmarshalPrimitiveMap(mdataIn);
mdataIn.close();
TypedProperties props = new TypedProperties();
loadMapIntoProperties(props, map);
props.encode(body.byteBuf());
}
use of org.apache.activemq.util.ByteArrayInputStream in project activemq-artemis by apache.
the class OpenWireMessageConverter method writeStreamType.
private static void writeStreamType(final ByteSequence contents, final boolean messageCompressed, final ActiveMQBuffer body) throws IOException {
InputStream sis = new ByteArrayInputStream(contents);
if (messageCompressed) {
sis = new InflaterInputStream(sis);
}
DataInputStream sdis = new DataInputStream(sis);
int stype = sdis.read();
while (stype != -1) {
switch(stype) {
case MarshallingSupport.BOOLEAN_TYPE:
body.writeByte(DataConstants.BOOLEAN);
body.writeBoolean(sdis.readBoolean());
break;
case MarshallingSupport.BYTE_TYPE:
body.writeByte(DataConstants.BYTE);
body.writeByte(sdis.readByte());
break;
case MarshallingSupport.BYTE_ARRAY_TYPE:
body.writeByte(DataConstants.BYTES);
int slen = sdis.readInt();
byte[] sbytes = new byte[slen];
sdis.read(sbytes);
body.writeInt(slen);
body.writeBytes(sbytes);
break;
case MarshallingSupport.CHAR_TYPE:
body.writeByte(DataConstants.CHAR);
char schar = sdis.readChar();
body.writeShort((short) schar);
break;
case MarshallingSupport.DOUBLE_TYPE:
body.writeByte(DataConstants.DOUBLE);
double sdouble = sdis.readDouble();
body.writeLong(Double.doubleToLongBits(sdouble));
break;
case MarshallingSupport.FLOAT_TYPE:
body.writeByte(DataConstants.FLOAT);
float sfloat = sdis.readFloat();
body.writeInt(Float.floatToIntBits(sfloat));
break;
case MarshallingSupport.INTEGER_TYPE:
body.writeByte(DataConstants.INT);
body.writeInt(sdis.readInt());
break;
case MarshallingSupport.LONG_TYPE:
body.writeByte(DataConstants.LONG);
body.writeLong(sdis.readLong());
break;
case MarshallingSupport.SHORT_TYPE:
body.writeByte(DataConstants.SHORT);
body.writeShort(sdis.readShort());
break;
case MarshallingSupport.STRING_TYPE:
body.writeByte(DataConstants.STRING);
String sstring = sdis.readUTF();
body.writeNullableString(sstring);
break;
case MarshallingSupport.BIG_STRING_TYPE:
body.writeByte(DataConstants.STRING);
String sbigString = MarshallingSupport.readUTF8(sdis);
body.writeNullableString(sbigString);
break;
case MarshallingSupport.NULL:
body.writeByte(DataConstants.STRING);
body.writeNullableString(null);
break;
default:
// something we don't know, ignore
break;
}
stype = sdis.read();
}
sdis.close();
}
use of org.apache.activemq.util.ByteArrayInputStream in project activemq-artemis by apache.
the class OpenWireMessageConverter method writeTextType.
private static void writeTextType(final ByteSequence contents, final boolean messageCompressed, final ActiveMQBuffer body) throws IOException {
InputStream tis = new ByteArrayInputStream(contents);
if (messageCompressed) {
tis = new InflaterInputStream(tis);
}
DataInputStream tdataIn = new DataInputStream(tis);
String text = MarshallingSupport.readUTF8(tdataIn);
tdataIn.close();
body.writeNullableSimpleString(new SimpleString(text));
}
Aggregations