• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert String to multiline InputStream  RSS feed

 
robert sturn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a String which is read from a socket.As the lines are read from Sockets I add each line to ArrayList.

Now I want to conevrt this ArrayList to InputStream.

I used
ArrayList message = inComingMessage;
txtMsg = message.toString()///This message contains a String

InputStream is = new ByteArrayInputStream(txtMsg.getBytes("UTF-8"));

When I read from is,I get entire message as in a one line where as my original message in ArrayList had multilines.



How can I get the original message that was read by socket.

Hope some one has faced this problem earlier
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the EOL characters? If you are getting '\n' from the socket and are on a Windows platform, BufferedReader will be looking for "\r\n" and give you one big line.
 
robert sturn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx for reply.
I am working on Windows.Client send \n as EOL.
Is there any workaround.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use String.split() to break the input String up and iterate over the returned array.
 
robert sturn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx Jess.

I resolved this by adding extra \n at the end of each line when I was populating ArrayList.

So my old code still works with this small change.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!