code: public void writeTo(DataOutputStream os) throws IOException
      {
      
      	int padding;
  		if (size<=4 && size>0) {
  			// Use small data element format (Page 1-10 in "MATLAB 7 MAT-File Format", September 2010 revision)
      		os.writeShort(size);
      		os.writeShort(type);
              padding = getPadding(data.limit(), true);
      	} else {
      		os.writeInt(type);
      		os.writeInt(size);
              padding = getPadding(data.limit(), false);
      	}
          
          int maxBuffSize = 1024;
          int writeBuffSize = data.remaining() < maxBuffSize ? data.remaining() : maxBuffSize;
          byte[] tmp = new byte[writeBuffSize]; 
          while ( data.remaining() > 0 )
          {
              int length = data.remaining() > tmp.length ? tmp.length : data.remaining();
              data.get( tmp, 0, length);
              os.write(tmp, 0, length);
          }
          
          if ( padding > 0 )
          {
              os.write( new byte[padding] );
          }
      }
docs: Writes tag and data to <code>DataOutputStream</code>. Wites padding if neccesary.
  
  @param os
  @throws IOException