Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Extract Header from Byte Array

Posted on 2009-04-02
1
Medium Priority
?
240 Views
Last Modified: 2013-11-23
I have a JAVA byte array which basically contains an http GET request.   That's what's I'm stuck with.  The real GET request looks like below in code window.

I need to extract header information from the byte array as a name value pair.  For example, the first set of values would look like this:
name= Host
value=www.msnbc.msn.com

GET requests will vary so the routine needs to handle *any* GET request.  That is, the number of name value pairs will vary.

I need each name value pair back as strings so I can place each value into another class.

It would be great if there was a routine that could do this like, GetNameValuePair (byte[] greq)

Would anyone be willing to provide a routine that could do this?





Realistic GET request stored in a byte array
----------------------------------------------------
GET / HTTP/1.1
Host: www.msnbc.msn.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12\n

Open in new window

0
Comment
Question by:lcor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
brunoguimaraes earned 2000 total points
ID: 24050043
You could use a Properties object.
byte[] header = // your byte array
 
Properties prop = new Properties();
 
prop.load(new ByteArrayInputStream(header));
 
// then you can retrieve the values this way:
prop.get("Host"); // prints www.msnbc.msn.com
 
// and so on...

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question