package com.weaver.seconddev.chapanda.test;

import java.io.*;
import java.util.UUID;

public class test12 {
    public static void main(String[] args) {
//        String data = "{observer={tenant_key=17416261816d5758, id={open_id=ou_4e198b58d57df5fb580d0f8922626f4a, union_id=on_cc2f4335bba6715b66258b019e39c185}}, profile_scene_id=scene-4, owner={tenant_key=17416261816d5758, id={open_id=ou_4e198b58d57df5fb580d0f8922626f4a, union_id=on_cc2f4335bba6715b66258b019e39c185}}}";
        String data = "{owner={tenant_key=17416261816d5758, id={open_id=ou_4e198b58d57df5fb580d0f8922626f4a, union_id=on_cc2f4335bba6715b66258b019e39c185}},observer={tenant_key=17416261816d5758, id={open_id=ou_4e198b58d57df5fb580d0f8922626f4a, union_id=on_cc2f4335bba6715b66258b019e39c185}}, profile_scene_id=scene-4}";

        if(data.contains("observer") && data.contains("owner")){
            int oberIndex = data.indexOf("observer");  //100
            int ownerIndex = data.indexOf("owner");  //10
            System.out.println("oberIndex:"+oberIndex);
            System.out.println("ownerIndex:"+ownerIndex);
            String ownerOpenId = "";
            String oberOpenId = "";
            if(oberIndex <= ownerIndex){
                String ownerData = data.substring(ownerIndex,data.length());
                String oberData = data.substring(oberIndex,ownerIndex);
                System.out.println("ownerData:{}"+ownerData);
                System.out.println("oberData:{}"+oberData);
                if(ownerData.contains("open_id")){
                    ownerData = ownerData.substring(ownerData.indexOf("open_id")+8);
                    if(ownerData.contains(",")){
                        ownerOpenId = ownerData.substring(0,ownerData.indexOf(","));
                    }
                }

                if(oberData.contains("open_id")){
                    oberData = oberData.substring(oberData.indexOf("open_id")+8);
                    System.out.println("oberData:"+oberData);
                    if(oberData.contains(",")){
                        oberOpenId = oberData.substring(0,oberData.indexOf(","));
                    }
                }
            }else{
                String oberData = data.substring(oberIndex,data.length());
                String ownerData = data.substring(ownerIndex,oberIndex);
                System.out.println("ownerData:{}"+ownerData);
                System.out.println("oberData:{}"+oberData);

                if(ownerData.contains("open_id")){
                    ownerData = ownerData.substring(ownerData.indexOf("open_id")+8);
                    if(ownerData.contains(",")){
                        ownerOpenId = ownerData.substring(0,ownerData.indexOf(","));
                    }
                }

                if(oberData.contains("open_id")){
                    oberData = oberData.substring(oberData.indexOf("open_id")+8);
                    System.out.println("oberData:"+oberData);
                    if(oberData.contains(",")){
                        oberOpenId = oberData.substring(0,oberData.indexOf(","));
                    }
                }

            }
            System.out.println("ownerOpenId:"+ownerOpenId);
            System.out.println("oberOpenId:"+oberOpenId);
        }


    }


    public static  byte[] convertInputStreamToBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        System.out.println("inputStream2:{}"+inputStream.available());
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            byteStream.write(buffer, 0, bytesRead);
        }
        System.out.println("byteStream:{}"+byteStream.toByteArray().length);
        return byteStream.toByteArray();
    }
}
