Package org.apache.activemq.util

Examples of org.apache.activemq.util.ByteArrayOutputStream


    }

    private void initializeWriting() throws MessageNotWriteableException {
        checkReadOnlyBody();
        if (this.dataOut == null) {
            this.bytesOut = new ByteArrayOutputStream();
            OutputStream os = bytesOut;
            ActiveMQConnection connection = getConnection();
            if (connection!=null && connection.isUseCompression()) {
                compressed = true;
                os = new DeflaterOutputStream(os);
View Full Code Here


    }

    public void write(Command command, SocketAddress address) throws IOException {
        synchronized (writeLock) {

            ByteArrayOutputStream largeBuffer = new ByteArrayOutputStream(defaultMarshalBufferSize);
            wireFormat.marshal(command, new DataOutputStream(largeBuffer));
            byte[] data = largeBuffer.toByteArray();
            int size = data.length;

            ByteBuffer writeBuffer = bufferPool.borrowBuffer();
            writeBuffer.clear();
            headerMarshaller.writeHeader(command, writeBuffer);
View Full Code Here

    }
   
    private void storeContent() {
        try {
            if( getContent()==null && !map.isEmpty()) {
                ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
                OutputStream os = bytesOut;
                ActiveMQConnection connection = getConnection();
                if( connection!= null && connection.isUseCompression() ) {
                    compressed = true;
                    os = new DeflaterOutputStream(os);
                }
                DataOutputStream dataOut = new DataOutputStream(os);
                MarshallingSupport.marshalPrimitiveMap(map, dataOut);
                dataOut.close();
                setContent(bytesOut.toByteSequence());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

  private static final int MAX_DATA_LENGTH = 1024*1024*100;
   
  private int version=1;

  public ByteSequence marshal(Object command) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        marshal(command, dos);
        dos.close();
        return baos.toByteSequence();
    }
View Full Code Here

     
      } else {

        // We don't know how much to read.. data ends when we hit a 0
          byte b;
          ByteArrayOutputStream baos=null;
          while ((b = in.readByte()) != 0) {
         
          if( baos == null ) {
              baos = new ByteArrayOutputStream();
            } else if( baos.size() > MAX_DATA_LENGTH ) {
              throw new ProtocolException("The maximum data length was exceeded", true);
            }
         
              baos.write(b);
          }
         
          if( baos!=null ) {
              baos.close();
              data = baos.toByteArray();
          }
         
      }
     
      return new StompFrame(action, headers, data);
View Full Code Here

    }

    private String readLine(DataInput in, int maxLength, String errorMessage) throws IOException {
        byte b;
        ByteArrayOutputStream baos=new ByteArrayOutputStream(maxLength);
        while ((b = in.readByte()) != '\n') {
          if( baos.size() > maxLength )
            throw new ProtocolException(errorMessage, true);
            baos.write(b);
        }
        ByteSequence sequence = baos.toByteSequence();
    return new String(sequence.getData(),sequence.getOffset(),sequence.getLength(),"UTF-8");
  }
View Full Code Here

            throw new ProtocolException("Unknown STOMP action: "+action);

        } catch (ProtocolException e) {

          // Let the stomp client know about any protocol errors.
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PrintWriter stream = new PrintWriter(new OutputStreamWriter(baos,"UTF-8"));
          e.printStackTrace(stream);
          stream.close();

          HashMap headers = new HashMap();
          headers.put(Stomp.Headers.Error.MESSAGE, e.getMessage());

            final String receiptId = (String) command.getHeaders().get(Stomp.Headers.RECEIPT_REQUESTED);
            if( receiptId != null ) {
              headers.put(Stomp.Headers.Response.RECEIPT_ID, receiptId);
            }

          StompFrame errorMessage = new StompFrame(Stomp.Responses.ERROR,headers,baos.toByteArray());
      sendToStomp(errorMessage);

      if( e.isFatal() )
        getTransportFilter().onException(e);
        }
View Full Code Here

    public void beforeMarshall(WireFormat wireFormat) throws IOException {
        super.beforeMarshall(wireFormat);
       
        ByteSequence content = getContent();
        if (content == null && text!=null ) {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            OutputStream os = bytesOut;
            ActiveMQConnection connection = getConnection();
            if( connection!=null && connection.isUseCompression() ) {
                compressed = true;
                os = new DeflaterOutputStream(os);
            }
            DataOutputStream dataOut = new DataOutputStream(os);
            MarshallingSupport.writeUTF8(dataOut, text);
            dataOut.close();
            setContent(bytesOut.toByteSequence());
        }
    }
View Full Code Here

    }

    public void beforeMarshall(WireFormat 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.toByteSequence();
        }
    }
View Full Code Here

    }

    public void beforeMarshall(WireFormat 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.toByteSequence();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.util.ByteArrayOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.