I am trying to read contents of a github repository. this is my code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
public class testInAction {
public static void main(String[] args) throws Throwable {
String link = "https://stash.gto.intranet.db.com:8081/projects/PARAGON/repos/paragongit/browse";
URL searchURL = new URL(link);
System.out.println("start");
HttpURLConnection searchHttp = (HttpURLConnection) searchURL.openConnection();
Map<String, List<String>> searchHeader = searchHttp.getHeaderFields();
InputStream searchStream = searchHttp.getInputStream();
String searchResponse = searchGetStringFromStream(searchStream);
System.out.println(searchResponse);
}
private static String searchGetStringFromStream(InputStream seachStream1) throws IOException {
if (seachStream1 != null) {
Writer searchWriter = new StringWriter();
char[] searchBuffer = new char[2048];
try {
Reader searchReader = new BufferedReader(new InputStreamReader(seachStream1, "UTF-8"));
int counter;
while ((counter = searchReader.read(searchBuffer)) != -1) {
searchWriter.write(searchBuffer, 0, counter);
}
}
finally {
seachStream1.close();
}
return searchWriter.toString();
} else {
return "No Contents";
}
}
}
I am getting Connect Exception on running this.
Исключение в потоке "main" java.net.ConnectException: Превышено время ожидания подключения: подключиться к sun.reflect.NativeConstructorAccessorImpl.newInstance0 (собственный метод) в sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImplj.jpg).в sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45) в java.lang.reflect.Constructor.newInstance (Constructor.java:423) в sun.net.www.protocol.http.HttpURLConnection $.Java: 1890) на sun.net.www.protocol.http.HttpURLConnection $ 10.run (HttpURLConnection.java:1885) на java.security.AccessController.doPrivileged (собственный метод) на sun.net.www.protocol.http.HttpURLConnection.getChainedException (HttpURLConnection.java:1884) в sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1457) в sun.net.www.protocol.http.HttpURLConnection.ttjurp (http:) на sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream (HttpsURLConnectionImpl.java:254) в testInAction.main (testInAction.java:34)