*
The moose likes Java in General and the fly likes If I use println to print out an input stream value, what should it look like? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "If I use println to print out an input stream value, what should it look like?" Watch "If I use println to print out an input stream value, what should it look like?" New topic
Author

If I use println to print out an input stream value, what should it look like?

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Feel free to just answer my topic question or read on to get a more detailed version of what Im asking -



When I print out some values to see what they are I get:



The first line, responseBody is of the type InputStream
The second line deviceCollection of the type DeviceCollection, in teh deviceContainer - It is this line I am mainly concered with. It is a stream so I had no idea what to expect when I print it out, just as long as it wasnt null!! But I dont know what to make of printing deviceCollection: deviceContainer.DeviceCollection@1764be1 - does this mean I actually was able to bind the responseBody to deviceCollection as a stream? (through this line: deviceCollection = access.readXML(method.getResponseBodyAsStream(null));)

And the third line data is of the type TreeNode, but that line is pretty obvious



So Im unsure how to interpret this. The first line seems to suggest it is working correctly right, because it is calling an auto close method on the stream right? However when I change some things in that class and try to also print out responseBody as a String, I get:



I think this also might be OK though, because if Im right it is saying it received the data I wanted and printed it out as a string, but when it also tried to print it as the stream, the stream was already closed. I think this is what this means, please clear this up for me though. deviceCOllection form teh third line also changes to null when I do this, but I would guess that is also the result of the stream being auto closed right?

It is this second line that Im mainly concerned with. Im trying to bind the responseBody which is that xml to deviceCollection. It seems I was successful in that first bit up there right? Or am I misinterpreting?


True wisdom is in knowing you know nothing - Socrates
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

All I can tell from that is that there's a device collection--its validity can only be determined by someone that knows what's supposed to be in it, what it's supposed to do, etc.

I can create all manner of objects and get their default toString() representation--their internal state is a completely different issue.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Here is the devicecollection class:



And the data that should be in deviceColelction is some xml froma web service:




I am trying to get it to this point, so I can then somehow bind the three nodes to a TreeNode, but I dont know hwo I am going to do so yet. One step at a time seeing as how Im learning a lot of this as I go


Is there a way I can see if the data contained therein is that xml I posted up there? I tried doing System.out.println("printing deviceCollection = access.readXML(method.getResponseBodyAsStream(null));: "
+ deviceCollection.toString());
but it gves me the exact same output as above. But I guess that is what you meant by it having a default toString representation. SO I guess I should say, is there a way for me to figure out what its internal state would be?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Loop over the devices and print something known from each device?
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

EUreka I think it is working!



returnes:







Ok, so where does this leave me now?
So now I know deviceCollection contains the intended value...finally after three days
OK, so what am I needing it to do now...

I will have to type this out again to get my thoughts flowing..

So deviceCOllection is of type DeviceCollection, which is just private Collection<Device> devices; with setter and getter...
the value contained in deviceCollection is an InputStream and looks like:



I am needing to take the value of each child node and bind it to something (TreeNode I think) and then I can use that to populate my richfaces tree.

Hmm, so something similar to the code I used to check the values it was holding would seem appropriate since it did return the value I was wanting.

I think Im close now, its so nice. Such a love hate relationship with programming. Trying to figure it out your in the lowest lows but when something work it is the highest high
 
 
subject: If I use println to print out an input stream value, what should it look like?
 
Similar Threads
trouble parsing stream or string into xml
XmlTreeDataBuilder Class inputsource question.
java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED)
How can I use println to display the value of data when I node.setData((TreeNode) deviceCollection..
rich:tree working now... all the work has finally paid off - THANKS