?
Solved

Serialize a HashMap into text?

Posted on 2009-04-21
7
Medium Priority
?
521 Views
Last Modified: 2012-05-06
Hi experts,

I need to store a HashMap as a bunch of bytes, and I could use serialization. But my keys and values are all strings, and in my system text processing is much faster. How could I encode it all into text? I stared by using newline as separator, but then I got into values that have newlines, and it all broke.

Thank you
0
Comment
Question by:kerzner
7 Comments
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 400 total points
ID: 24194134
you can wrap the key and value string into single/double quote and escape the quote if it occurs with in the string.
0
 
LVL 12

Accepted Solution

by:
Gibu George earned 1600 total points
ID: 24194156
If the keys and values are text use properties instead of hashmap, there are methods load() and store(0 methods which allows you to write to a property file and read from there
0
 
LVL 1

Author Comment

by:kerzner
ID: 24194159
Let me try...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Gibu George
ID: 24194175
If you are using Java 1.5 then there is option to storeToXMl and loadFromXML also
0
 
LVL 1

Author Comment

by:kerzner
ID: 24194205
Let me try that too - that would be more automatic
0
 
LVL 11

Expert Comment

by:Steiner
ID: 24195027
You can also have look at XStream for serialization to XML, even with Java 1.4.
0
 
LVL 1

Author Closing Comment

by:kerzner
ID: 31572718
load() and store() worked, and if I need text-only later on, I'll use the quote escape
Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 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