All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.diagnostic.DevelopersLoader Maven / Gradle / Ivy

/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.diagnostic;

import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.util.io.HttpRequests;
import org.jetbrains.annotations.NotNull;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

class DevelopersLoader {
  private static final String DEVELOPERS_LIST_URL = "http://ea-engine.labs.intellij.net/data?category=developers";
  public static final int TIMEOUT = 1000;

  private DevelopersLoader() {
  }

  public static Collection fetchDevelopers(@NotNull final ProgressIndicator indicator) throws IOException {
    return HttpRequests.request(DEVELOPERS_LIST_URL).connect(new HttpRequests.RequestProcessor>() {
      @Override
      public Collection process(@NotNull HttpRequests.Request request) throws IOException {
        List developers = new LinkedList();
        developers.add(Developer.NULL);
        BufferedReader reader = request.getReader();
        while (true) {
          String line = reader.readLine();
          if (line == null) break;
          int i = line.indexOf('\t');
          if (i == -1) throw new IOException("Protocol error");
          int id = Integer.parseInt(line.substring(0, i));
          String name = line.substring(i + 1);
          developers.add(new Developer(id, name));
          indicator.checkCanceled();
        }
        return developers;
      }
    });
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy