• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simulating byte stream

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to get stream of data that will simulate like:

http://developer.apple.com/IPhone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Art/aps_feedback_binary.jpg

This will be 38 bytes (4+2+32) data in one token. I need to have series of such tokens where I can actually store the data and use if for my purpose of testing my application.

The actual data will be 64 character long (HEXA Decimal) string.

Any idea how to have this stream simulation.


Thanks in advance.
~Chandra
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How about creating a pair of piped streams? Use the input steam as you would use the actual stream. As for the output stream, you can create new thread that will do nothing but write tokens into it.

Henry
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks henry,


I need group of such 38 bytes token in a byte stream, that I could pass to method that does tokenize/parsing it.

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the data I want to put in and then convert to byte stream
{time_t = 1268360515647
sizeof the token (2 bytes)
token data = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdddd"}


It is difficult to get the real data stream for testing my application, as it only comes from the production environment. I wanted to have such simulated stream for testing
purpose.

Here I need dummy/simulated replacement for socket.getInputStream()...
So wanted to create a stream of tokens with appropriated values and test my this method which actually parses/tokenizes/extracts the data:




Thanks
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea on this please
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra Bhatt wrote:Any idea on this please



On what? Are you asking if the pipe stream can handle this? or is asking another question, like how to package the bytes?

Henry
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Chandra Bhatt wrote:Any idea on this please



On what? Are you asking if the pipe stream can handle this? or is asking another question, like how to package the bytes?

Henry



My question is on how to package the bytes. Or in other words how to get streamed of tokens for my application, say Output stream containing tokens.
Bare with this, if I am asking something trivial to do. Not sure though.
 
Paul Clapham
Sheriff
Posts: 21002
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all there is ByteArrayInputStream. You could use a ByteArrayInputStream which wraps one of your 64-byte tokens.

Then there is SequenceInputStream which allows you to concatenate input streams. If you provided something which produced an Enumeration of the ByteArrayInputStreams which wrapped your tokens, you would be done.
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra Bhatt wrote:
My question is on how to package the bytes. Or in other words how to get streamed of tokens for my application, say Output stream containing tokens.
Bare with this, if I am asking something trivial to do. Not sure though.


Converting any data type to an array of bytes can simply be done via bit shifting, and the AND and OR operators. Or you can use the ByteBuffer class.

Henry
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry.. It did help me. I was able to do using ByteBuffer.
Thanks a lot.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic