The STUN packet format is explained in perfect detail in RFC 5389.
If you want decent Java code for STUN - go take a look at JSTUN sources. It's pretty easy to use their library and/or modify their code.
If you want to use my code, written in C++, you can peruse the sources of Stuntman. There's both a parser class (CStunReader) and a class to create STUN messages (CStunWriter).