Search in sources :

Example 1 with ByteArrayInputStream

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;
}
Also used : StatusLine(org.apache.http.StatusLine) HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion)

Example 2 with ByteArrayInputStream

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();
    }
}
Also used : ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with ByteArrayInputStream

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());
}
Also used : ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DataInputStream(java.io.DataInputStream) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties)

Example 4 with ByteArrayInputStream

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();
}
Also used : ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DataInputStream(java.io.DataInputStream)

Example 5 with ByteArrayInputStream

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));
}
Also used : ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DataInputStream(java.io.DataInputStream)

Aggregations

ByteArrayInputStream (org.apache.activemq.util.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)4 InputStream (java.io.InputStream)4 InflaterInputStream (java.util.zip.InflaterInputStream)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Response (javax.ws.rs.core.Response)1 XPath (javax.xml.xpath.XPath)1 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 ProtocolVersion (org.apache.http.ProtocolVersion)1 StatusLine (org.apache.http.StatusLine)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.hasXPath (org.hamcrest.Matchers.hasXPath)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1