Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/transport/stomp/HeaderParser.java


1   /*
2    * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3    */
4   package org.activemq.transport.stomp;
5   
6   import java.io.BufferedReader;
7   import java.io.DataInput;
8   import java.io.IOException;
9   import java.util.Properties;
10  import java.net.ProtocolException;
11  
12  class HeaderParser
13  {
14      /**
15       * Reads headers up through the blank line
16       *
17       * @param in
18       * @return
19       * @throws IOException
20       */
21      Properties parse(BufferedReader in) throws IOException
22      {
23          Properties props = new Properties();
24          String line;
25          while (((line = in.readLine()).trim().length() > 0))
26          {
27              int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
28              String name = line.substring(0, seperator_index).trim();
29              String value = line.substring(seperator_index + 1, line.length()).trim();
30              props.setProperty(name, value);
31          }
32          return props;
33      }
34  
35      Properties parse(DataInput in) throws IOException
36      {
37          Properties props = new Properties();
38          String line;
39          while (((line = in.readLine()).trim().length() > 0))
40          {
41              try
42              {
43                  int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
44                  String name = line.substring(0, seperator_index).trim();
45                  String value = line.substring(seperator_index + 1, line.length()).trim();
46                  props.setProperty(name, value);
47              }
48              catch (Exception e)
49              {
50                  throw new ProtocolException("Unable to parser header line [" + line + "]");
51              }
52          }
53          return props;
54      }
55  }