static GsonBuilder gsonBuilder = new GsonBuilder();

  static Gson gson = gsonBuilder.create();

  static int START = 47554551;

  static int MAX   = 47980000;

  static int STEP = 500;

  static BufferedWriter writer = null;

  private static void chatRun() throws InvalidFormatException, InterruptedException {

   

   try {

    URL u = null;

    HttpURLConnection con = null;

    System.out.println("시작");

     if(START > MAX) {

      System.out.println("종료");

     }else{

      u = new URL("https://www.bitmex.com/api/v1/chat?count="+STEP+"&start="+START+"&reverse=false&channelID=4");

      System.out.println("https://www.bitmex.com/api/v1/chat?count="+STEP+"&start="+START+"&reverse=false&channelID=4");

      con = (HttpURLConnection) u.openConnection();

      StringBuilder sb = new StringBuilder();

      if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {

       BufferedReader br = new BufferedReader(

         new InputStreamReader(con.getInputStream(), "utf-8"));

       String line;

       while ((line = br.readLine()) != null) {

        sb.append(line+"\n");

       }

       

       br.close();

       chatVO[] vo = gson.fromJson(sb.toString(), chatVO[].class);

       ArrayList<chatVO> arrayList = new ArrayList<>(Arrays.asList(vo));

       

       for( chatVO item : arrayList) {

        if(!item.isFromBot()) {

         String txt = item.getDate()+" \t "+item.getId()+" \t "+item.getUser()+" \t "+item.getMessage()+"\n";

         writer.append(txt);

        }

       }

       

       START = START+STEP;

       con.disconnect();

       Thread.sleep(3000);

       chatRun();

     } else {

      System.out.println(con.getResponseMessage());

     }

    }

   } catch (IOException e) {

    e.fillInStackTrace();

   }

  }