| Author |
Simulating byte stream
|
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
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
|
cmbhatt
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16683
|
|
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
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
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
Joined: Feb 28, 2007
Posts: 1707
|
|
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
Joined: Feb 28, 2007
Posts: 1707
|
|
|
Any idea on this please
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16683
|
|
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
Joined: Feb 28, 2007
Posts: 1707
|
|
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
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
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
Sheriff
Joined: Sep 28, 2004
Posts: 16683
|
|
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
Joined: Feb 28, 2007
Posts: 1707
|
|
Thanks Henry.. It did help me. I was able to do using ByteBuffer.
Thanks a lot.
|
 |
 |
|
|
subject: Simulating byte stream
|
|
|