Package org.activemq.transport.stomp

Source Code of org.activemq.transport.stomp.HeaderParser

/*
* Copyright (c) 2005 Your Corporation. All Rights Reserved.
*/
package org.activemq.transport.stomp;

import java.io.BufferedReader;
import java.io.DataInput;
import java.io.IOException;
import java.util.Properties;
import java.net.ProtocolException;

class HeaderParser
{
    /**
     * Reads headers up through the blank line
     *
     * @param in
     * @return
     * @throws IOException
     */
    Properties parse(BufferedReader in) throws IOException
    {
        Properties props = new Properties();
        String line;
        while (((line = in.readLine()).trim().length() > 0))
        {
            int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
            String name = line.substring(0, seperator_index).trim();
            String value = line.substring(seperator_index + 1, line.length()).trim();
            props.setProperty(name, value);
        }
        return props;
    }

    Properties parse(DataInput in) throws IOException
    {
        Properties props = new Properties();
        String line;
        while (((line = in.readLine()).trim().length() > 0))
        {
            try
            {
                int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
                String name = line.substring(0, seperator_index).trim();
                String value = line.substring(seperator_index + 1, line.length()).trim();
                props.setProperty(name, value);
            }
            catch (Exception e)
            {
                throw new ProtocolException("Unable to parser header line [" + line + "]");
            }
        }
        return props;
    }
}
TOP

Related Classes of org.activemq.transport.stomp.HeaderParser

TOP
Copyright © 2018 www.massapi.com. 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.