if(prefixCounter) { long id = sent + 1; ByteArrayOutputStream os = new ByteArrayOutputStream(message.length + 15); os.write(new AsciiBuffer(Long.toString(id))); os.write(':'); os.write(body); message = os.toBuffer();
public void beforeMarshall(OpenWireFormat wireFormat) throws IOException { // Need to marshal the properties. if (marshalledProperties == null && properties != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); MarshallingSupport.marshalPrimitiveMap(properties, os); os.close(); marshalledProperties = baos.toBuffer(); } }
@Override public void delivery(Delivery delivery) throws Exception { if (!delivery.isReadable()) { LOG.debug("Delivery was not readable!"); return; } if (current == null) { current = new ByteArrayOutputStream(); } int count; while ((count = getEndpoint().recv(recvBuffer, 0, recvBuffer.length)) > 0) { current.write(recvBuffer, 0, count); if (current.size() > session.getMaxFrameSize()) { throw new AmqpProtocolException("Frame size of " + current.size() + " larger than max allowed " + session.getMaxFrameSize()); } } // Expecting more deliveries.. if (count == 0) { return; } try { processDelivery(delivery, current.toBuffer()); } finally { getEndpoint().advance(); current = null; } }
public static String decodeHeader(Buffer value) { if (value == null) return null; ByteArrayOutputStream rc = new ByteArrayOutputStream(value.length); Buffer pos = new Buffer(value); int max = value.offset + value.length; while (pos.offset < max) { if (pos.startsWith(ESCAPE_ESCAPE_SEQ)) { rc.write(ESCAPE_BYTE); pos.moveHead(2); } else if (pos.startsWith(COLON_ESCAPE_SEQ)) { rc.write(COLON_BYTE); pos.moveHead(2); } else if (pos.startsWith(NEWLINE_ESCAPE_SEQ)) { rc.write(NEWLINE_BYTE); pos.moveHead(2); } else { rc.write(pos.data[pos.offset]); pos.moveHead(1); } } try { return new String(rc.toByteArray(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // not expected. } }
private void storeContent() { if (dataOut != null) { try { dataOut.close(); setContent(bytesOut.toBuffer()); bytesOut = null; dataOut = null; } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
private void initializeWriting() throws OpenwireException { checkReadOnlyBody(); if (this.dataOut == null) { this.bytesOut = new ByteArrayOutputStream(); OutputStream os = bytesOut; if (Settings.enable_compression()) { compressed = true; os = new DeflaterOutputStream(os); } this.dataOut = new DataOutputStream(os); } }
public static byte[] readBytes(InputStream in) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyInputStream(in, baos); return baos.toByteArray(); }
public void write(Buffer b) { write(b.data, b.offset, b.length); }
public void write(int b) { int newsize = size + 1; checkCapacity(newsize); buffer[size] = (byte) b; size = newsize; }
public void beforeMarshall(OpenWireFormat wireFormat) throws IOException { // Need to marshal the properties. if (marshalledProperties == null && properties != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); MarshallingSupport.marshalPrimitiveMap(properties, os); os.close(); marshalledProperties = baos.toBuffer(); } }
@Override public void delivery(Delivery delivery) throws Exception { if (!delivery.isReadable()) { LOG.debug("Delivery was not readable!"); return; } if (current == null) { current = new ByteArrayOutputStream(); } int count; while ((count = getEndpoint().recv(recvBuffer, 0, recvBuffer.length)) > 0) { current.write(recvBuffer, 0, count); if (current.size() > session.getMaxFrameSize()) { throw new AmqpProtocolException("Frame size of " + current.size() + " larger than max allowed " + session.getMaxFrameSize()); } } // Expecting more deliveries.. if (count == 0) { return; } try { processDelivery(delivery, current.toBuffer()); } finally { getEndpoint().advance(); current = null; } }
public static String decodeHeader(Buffer value) { if (value == null) return null; ByteArrayOutputStream rc = new ByteArrayOutputStream(value.length); Buffer pos = new Buffer(value); int max = value.offset + value.length; while (pos.offset < max) { if (pos.startsWith(ESCAPE_ESCAPE_SEQ)) { rc.write(ESCAPE_BYTE); pos.moveHead(2); } else if (pos.startsWith(COLON_ESCAPE_SEQ)) { rc.write(COLON_BYTE); pos.moveHead(2); } else if (pos.startsWith(NEWLINE_ESCAPE_SEQ)) { rc.write(NEWLINE_BYTE); pos.moveHead(2); } else { rc.write(pos.data[pos.offset]); pos.moveHead(1); } } try { return new String(rc.toByteArray(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // not expected. } }
private void storeContent() { if (dataOut != null) { try { dataOut.close(); setContent(bytesOut.toBuffer()); bytesOut = null; dataOut = null; } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
private void initializeWriting() throws OpenwireException { checkReadOnlyBody(); if (this.dataOut == null) { this.bytesOut = new ByteArrayOutputStream(); OutputStream os = bytesOut; if (Settings.enable_compression()) { compressed = true; os = new DeflaterOutputStream(os); } this.dataOut = new DataOutputStream(os); } }
public void write(Buffer b) { write(b.data, b.offset, b.length); }
public void write(int b) { int newsize = size + 1; checkCapacity(newsize); buffer[size] = (byte) b; size = newsize; }
public static AsciiBuffer encodeHeader(String value) { if (value == null) return null; try { byte[] data = value.getBytes("UTF-8"); ByteArrayOutputStream rc = new ByteArrayOutputStream(data.length); for (byte d : data) { switch (d) { case ESCAPE_BYTE: rc.write(ESCAPE_ESCAPE_SEQ); break; case COLON_BYTE: rc.write(COLON_ESCAPE_SEQ); break; case NEWLINE_BYTE: rc.write(COLON_ESCAPE_SEQ); break; default: rc.write(d); } } return rc.toBuffer().ascii(); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // not expected. } }
public void beforeMarshall(OpenWireFormat wireFormat) throws IOException { // Need to marshal the properties. if (marshalledProperties == null && properties != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); MarshallingSupport.marshalPrimitiveMap(properties, os); os.close(); marshalledProperties = baos.toBuffer(); } }
public byte[] toByteArray() { return toBuffer().toByteArray(); }
private void initializeWriting() throws OpenwireException { checkReadOnlyBody(); if (this.dataOut == null) { this.bytesOut = new ByteArrayOutputStream(); OutputStream os = bytesOut; if (Settings.enable_compression()) {