Don’t forget to flush!

It’s been a rough day. I spent the majority of it chasing down random misbehavior on a staging server. My development machine is 32 bit. (Technically my development machine is 64 bit but I’m running a 32bit Kernel in my OS.) The staging server is 64bit. I write Java. Java sez, “you write once and run anywhere!” In reality, when I move compiled source code from my development machine to my staging machine things act radically different.

The big picture is that I’m trying to make the staging machine talk to me. I mean literally talk, using english words and all. It’s the extra 32 bits in this staging machine that have been getting in the way. They force me to scour the web and find native libraries that contain the same amount of extra chromosomes… err… bits. Then on top of that, Tomcat likes to do different things when you throw war files in it.

Today’s lesson begins from Tomcat. Pretend you’ve written a servlet. (Ok, you don’t have to pretend. Go on and write a servlet if it makes you feel better, I’ll wait here patiently.) In your servlet make like you have a lot of binary stuff that you want to share with connecting web people. These people might be sitting under a MacbookPro, or scrolling a Blackberry wheel, or flicking an iPhone or something. Whatever the case, they came to your servlet to get these wonderful binary thingies. These binary thingies are larger than your typical web page, spanning a few kilobytes. So now you have to use one of those stream classes. If you’re really smart, like I think I am, then you’ll do something clever [stupid] and try pipelining, or reading from an input stream and writing to an output stream. You’ll do this because you’re afraid of materializing too much binary goodness in your precious RAM sticks. You’ll say “1024 bytes is plenty enough! Let’s take these one thousand twenty four bytes and put them on the output stream for the people can get those!” Then if you’re really really smart, you’ll do this in a loop until you reach the bottom of your input stream.

Are you all done with your computer program? I think I’m done with mine! Goody! Lets mash the run button and see what happens? Is yourz doing like mine isn’t doing? Minez is supposed to be shuttling all of the binary stuff across teh internets, but its not because its borked. I only get part of what I thought I was gonna git. Now go scratch your head like the guys in the head and shoulders commercials and pour another cup of coffee. when you get back we’ll figure out wha happend…

Are you back yet? Cool! Lets look into your really really smart looping program. Do you see it? Right there in the middle of your loop. You keep writin’ stuff but only part of it is showing on the other end. Any idea why? My Mommy told me a long time ago, “never forget to flush! It’s just bad manners…” She was also famous for saying stuff like, “poop or get off the pot!” In the loop thing we never flush our output stream! Maybe that’s why we only see a part of the stuff on the other end. So then there’s a happy ending to the story after all isn’t there?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s