public static InputStream storeMapToStream(String key, Map<String, Object> m, String type)
            throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeUTF(key);
        writeMapToStream(m, dos);
        // add the type in
        dos.writeUTF(type);
        dos.flush();
        baos.flush();
        byte[] b = baos.toByteArray();
        baos.close();
        dos.close();
        return new ByteArrayInputStream(b);
    }
public static InputStream storeMapToStream ( String key , Map < String , Object > m , String type ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; DataOutputStream dos = new DataOutputStream ( baos ) ; dos . writeUTF ( key ) ; writeMapToStream ( m , dos ) ; dos . writeUTF ( type ) ; dos . flush ( ) ; baos . flush ( ) ; byte [ ] b = baos . toByteArray ( ) ; baos . close ( ) ; dos . close ( ) ; return new ByteArrayInputStream ( b ) ; }
the data isnt there. See the last writeUTF for an example.