@Override protected void doCompress() throws IOException { compressed = true; ByteSequence bytes = getContent(); if (bytes != null) { int length = bytes.getLength(); ByteArrayOutputStream compressed = new ByteArrayOutputStream(); compressed.write(new byte[4]); Deflater deflater = new Deflater(); try { deflater.setInput(bytes.data); deflater.finish(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); compressed.write(buffer, 0, count); } bytes = compressed.toByteSequence(); ByteSequenceData.writeIntBig(bytes, length); bytes.offset = 0; setContent(bytes); } finally { deflater.end(); compressed.close(); } } } }
private void initializeReading() throws JMSException { checkWriteOnlyBody(); if (dataIn == null) { try { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { if (data.length != 0) { is = new ByteArrayInputStream(decompress(data)); } } else { length = data.getLength(); } dataIn = new DataInputStream(is); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } } }
@Override public <T> T getBody(final Class<T> c) throws JMSException { final int len = (int) getBodyLength(); if (len == 0) { return null; } final byte[] dst = new byte[len]; if (ActiveMQBytesMessage.class.isInstance(message)) { System.arraycopy(ActiveMQBytesMessage.class.cast(message).getContent().getData(), 0, dst, 0, len); } return c.cast(dst); }
private void initializeReading() throws JMSException { checkWriteOnlyBody(); if (dataIn == null) { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { // keep track of the real length of the content if // we are compressed. try { DataInputStream dis = new DataInputStream(is); length = dis.readInt(); dis.close(); } catch (IOException e) { throw JMSExceptionSupport.create(e); } is = new InflaterInputStream(is); } else { length = data.getLength(); } dataIn = new DataInputStream(is); } }
@Override protected void doCompress() throws IOException { compressed = true; ByteSequence bytes = getContent(); if (bytes != null) { int length = bytes.getLength(); ByteArrayOutputStream compressed = new ByteArrayOutputStream(); compressed.write(new byte[4]); Deflater deflater = new Deflater(); try { deflater.setInput(bytes.data); deflater.finish(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); compressed.write(buffer, 0, count); } bytes = compressed.toByteSequence(); ByteSequenceData.writeIntBig(bytes, length); bytes.offset = 0; setContent(bytes); } finally { deflater.end(); compressed.close(); } } } }
private void initListener() { try { consumer.setMessageListener(message -> { if (message instanceof BytesMessage) { ByteSequence bs = ((ActiveMQBytesMessage) message).getContent(); eventProcessor.onEvent(bs.getData()); } }); } catch (JMSException e) { e.printStackTrace(); } }
private void initListener() { try { consumer.setMessageListener(message -> { if (message instanceof BytesMessage) { ByteSequence bs = ((ActiveMQBytesMessage) message).getContent(); eventProcessor.onEvent(bs.getData()); } }); } catch (JMSException e) { e.printStackTrace(); } }
@Override protected void doCompress() throws IOException { compressed = true; ByteSequence bytes = getContent(); if (bytes != null) { int length = bytes.getLength(); ByteArrayOutputStream compressed = new ByteArrayOutputStream(); compressed.write(new byte[4]); Deflater deflater = new Deflater(); try { deflater.setInput(bytes.data); deflater.finish(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); compressed.write(buffer, 0, count); } bytes = compressed.toByteSequence(); ByteSequenceData.writeIntBig(bytes, length); bytes.offset = 0; setContent(bytes); } finally { deflater.end(); compressed.close(); } } } }
@Override protected void doCompress() throws IOException { compressed = true; ByteSequence bytes = getContent(); if (bytes != null) { int length = bytes.getLength(); ByteArrayOutputStream compressed = new ByteArrayOutputStream(); compressed.write(new byte[4]); Deflater deflater = new Deflater(); try { deflater.setInput(bytes.data); deflater.finish(); byte[] buffer = new byte[1024]; while (!deflater.finished()) { int count = deflater.deflate(buffer); compressed.write(buffer, 0, count); } bytes = compressed.toByteSequence(); ByteSequenceData.writeIntBig(bytes, length); bytes.offset = 0; setContent(bytes); } finally { deflater.end(); compressed.close(); } } } }
/** * Return the encoded form of the BytesMessage as an AMQP Binary instance. * * @param message * the Message whose binary encoded body is needed. * * @return a Binary instance containing the encoded message body. * * @throws JMSException if an error occurs while fetching the binary payload. */ public static Binary getBinaryFromMessageBody(ActiveMQBytesMessage message) throws JMSException { Binary result = null; if (message.getContent() != null) { ByteSequence contents = message.getContent(); if (message.isCompressed()) { int length = (int) message.getBodyLength(); byte[] uncompressed = new byte[length]; message.readBytes(uncompressed); result = new Binary(uncompressed); } else { return new Binary(contents.getData(), contents.getOffset(), contents.getLength()); } } return result; }
/** * Return the encoded form of the BytesMessage as an AMQP Binary instance. * * @param message * the Message whose binary encoded body is needed. * * @return a Binary instance containing the encoded message body. * * @throws JMSException if an error occurs while fetching the binary payload. */ public static Binary getBinaryFromMessageBody(ActiveMQBytesMessage message) throws JMSException { Binary result = null; if (message.getContent() != null) { ByteSequence contents = message.getContent(); if (message.isCompressed()) { int length = (int) message.getBodyLength(); byte[] uncompressed = new byte[length]; message.readBytes(uncompressed); result = new Binary(uncompressed); } else { return new Binary(contents.getData(), contents.getOffset(), contents.getLength()); } } return result; }
private void initializeReading() throws JMSException { checkWriteOnlyBody(); if (dataIn == null) { try { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { if (data.length != 0) { is = new ByteArrayInputStream(decompress(data)); } } else { length = data.getLength(); } dataIn = new DataInputStream(is); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } } }
private void initializeReading() throws JMSException { checkWriteOnlyBody(); if (dataIn == null) { try { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { if (data.length != 0) { is = new ByteArrayInputStream(decompress(data)); } } else { length = data.getLength(); } dataIn = new DataInputStream(is); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } } }
private void initializeReading() throws JMSException { checkWriteOnlyBody(); if (dataIn == null) { try { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { if (data.length != 0) { is = new ByteArrayInputStream(decompress(data)); } } else { length = data.getLength(); } dataIn = new DataInputStream(is); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } } }