private String decodeContent(ByteSequence bodyAsBytes) throws JMSException { String text = null; if (bodyAsBytes != null) { InputStream is = null; try { is = new ByteArrayInputStream(bodyAsBytes); if (isCompressed()) { is = new InflaterInputStream(is); } DataInputStream dataIn = new DataInputStream(is); text = MarshallingSupport.readUTF8(dataIn); dataIn.close(); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // ignore } } } } return text; }
public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
public Object unmarshal(ByteSequence packet) throws IOException { return unmarshal(new DataInputStream(new ByteArrayInputStream(packet))); }
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: case MarshallingSupport.BIG_STRING_TYPE: body.writeByte(DataConstants.STRING); String sbigString = MarshallingSupport.readUTF8(sdis); body.writeNullableString(sbigString); break;
private Map<String, Object> unmarsallProperties(ByteSequence marshalledProperties) throws IOException { return MarshallingSupport.unmarshalPrimitiveMap(new DataInputStream(new ByteArrayInputStream(marshalledProperties)), MAX_PROPERTY_SIZE); }
try (ByteArrayInputStream is = new ByteArrayInputStream(contents); InflaterInputStream iis = new InflaterInputStream(is); DataInputStream dis = new DataInputStream(iis);) { int size = dis.readInt(); byte[] uncompressed = new byte[size]; dis.readFully(uncompressed); result = new Binary(contents.getData(), contents.getOffset() + 4, contents.getLength() - 4);
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); } }
private void initializeReading() throws MessageNotReadableException { checkWriteOnlyBody(); if (this.dataIn == null) { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { is = new InflaterInputStream(is); is = new BufferedInputStream(is); } this.dataIn = new DataInputStream(is); } }
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); } } }
try { if (compressed) { ByteArrayInputStream input = new ByteArrayInputStream(this.content.getData(), this.content.getOffset(), this.content.getLength()); InflaterInputStream inflater = new InflaterInputStream(input); try { byte[] buffer = new byte[8*1024]; int read = 0; while ((read = inflater.read(buffer)) != -1) { this.dataOut.write(buffer, 0, read); inflater.close();
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(); } }
ByteArrayInputStream headerLine = new ByteArrayInputStream(line); ByteArrayOutputStream stream = new ByteArrayOutputStream(line.length); while ((result = headerLine.read()) != -1) { if (result != ':') { stream.write(result); String name = new String(nameSeq.getData(), nameSeq.getOffset(), nameSeq.getLength(), "UTF-8"); String value = decodeHeader(headerLine); if (stompVersion.equals(Stomp.V1_0)) {
/** * @see org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter#setBinaryData(java.sql.PreparedStatement, * int, byte[]) */ @Override protected void setBinaryData(PreparedStatement s, int index, byte[] data) throws SQLException { s.setBinaryStream(index, new ByteArrayInputStream(data), data.length); }
public Command read() throws IOException { Command answer = null; Endpoint from = null; synchronized (readLock) { while (true) { DatagramPacket datagram = createDatagramPacket(); channel.receive(datagram); // TODO could use a DataInput implementation that talks direct // to the byte[] to avoid object allocation receiveCounter++; DataInputStream dataIn = new DataInputStream(new ByteArrayInputStream(datagram.getData(), 0, datagram.getLength())); from = headerMarshaller.createEndpoint(datagram, dataIn); answer = (Command)wireFormat.unmarshal(dataIn); break; } } if (answer != null) { answer.setFrom(from); if (LOG.isDebugEnabled()) { LOG.debug("Channel: " + name + " about to process: " + answer); } } return answer; }
private Map<String, Object> unmarsallProperties(ByteSequence marshalledProperties) throws IOException { return MarshallingSupport.unmarshalPrimitiveMap(new DataInputStream(new ByteArrayInputStream(marshalledProperties))); }
try (ByteArrayInputStream is = new ByteArrayInputStream(contents); InflaterInputStream iis = new InflaterInputStream(is); DataInputStream dis = new DataInputStream(iis);) { int size = dis.readInt(); byte[] uncompressed = new byte[size]; dis.readFully(uncompressed); result = new Binary(contents.getData(), contents.getOffset() + 4, contents.getLength() - 4);
private void initializeReading() throws MessageNotReadableException { checkWriteOnlyBody(); if (this.dataIn == null) { ByteSequence data = getContent(); if (data == null) { data = new ByteSequence(new byte[] {}, 0, 0); } InputStream is = new ByteArrayInputStream(data); if (isCompressed()) { is = new InflaterInputStream(is); is = new BufferedInputStream(is); } this.dataIn = new DataInputStream(is); } }
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); } } }
try { if (compressed) { ByteArrayInputStream input = new ByteArrayInputStream(this.content.getData(), this.content.getOffset(), this.content.getLength()); InflaterInputStream inflater = new InflaterInputStream(input); try { byte[] buffer = new byte[8*1024]; int read = 0; while ((read = inflater.read(buffer)) != -1) { this.dataOut.write(buffer, 0, read); inflater.close();
ByteArrayInputStream headerLine = new ByteArrayInputStream(line); ByteArrayOutputStream stream = new ByteArrayOutputStream(line.length); while ((result = headerLine.read()) != -1) { if (result != ':') { stream.write(result); String name = new String(nameSeq.getData(), nameSeq.getOffset(), nameSeq.getLength(), "UTF-8"); String value = decodeHeader(headerLine); if (stompVersion.equals(Stomp.V1_0)) {