Here you can find the source of writeStringData(DataOutputStream mDataOutputStream, String token)
public static void writeStringData(DataOutputStream mDataOutputStream, String token) throws IOException
//package com.java2s; //License from project: Apache License import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { public static void writeStringData(DataOutputStream mDataOutputStream, String token) throws IOException { byte[] name = token.getBytes(); mDataOutputStream.write(ByteBuffer.allocate(4).putInt(name.length).array()); mDataOutputStream.flush();//from w w w. j a va 2s. com mDataOutputStream.write(name); mDataOutputStream.flush(); } }