Tabnine Logo
HttpURLConnection.getContent
Code IndexAdd Tabnine to your IDE (free)

How to use
getContent
method
in
java.net.HttpURLConnection

Best Java code snippets using java.net.HttpURLConnection.getContent (Showing top 20 results out of 2,421)

origin: square/okhttp

@Override public Object getContent(Class[] types) throws IOException {
 return delegate.getContent(types);
}
origin: square/okhttp

@Override public Object getContent() throws IOException {
 return delegate.getContent();
}
origin: prestodb/presto

@SuppressWarnings("unchecked") // Spec does not generify
@Override public Object getContent(Class[] types) throws IOException {
 return delegate.getContent(types);
}
origin: prestodb/presto

@Override public Object getContent() throws IOException {
 return delegate.getContent();
}
origin: checkstyle/checkstyle

private static boolean isUrlReachable(String url) {
  boolean result = true;
  try {
    final URL verifiableUrl = new URL(url);
    final HttpURLConnection urlConnect = (HttpURLConnection) verifiableUrl.openConnection();
    urlConnect.getContent();
  }
  catch (IOException ignored) {
    result = false;
  }
  return result;
}
origin: checkstyle/checkstyle

private static boolean isUrlReachable(String url) {
  boolean result = true;
  try {
    final URL verifiableUrl = new URL(url);
    final HttpURLConnection urlConnect = (HttpURLConnection) verifiableUrl.openConnection();
    urlConnect.getContent();
  }
  catch (IOException ignored) {
    result = false;
  }
  return result;
}
origin: Netflix/Priam

public static String getDataFromUrl(String url) {
  try {
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setConnectTimeout(1000);
    conn.setReadTimeout(1000);
    conn.setRequestMethod("GET");
    if (conn.getResponseCode() != 200) {
      throw new RuntimeException("Unable to get data for URL " + url);
    }
    byte[] b = new byte[2048];
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataInputStream d = new DataInputStream((FilterInputStream) conn.getContent());
    int c;
    while ((c = d.read(b, 0, b.length)) != -1) bos.write(b, 0, c);
    String return_ = new String(bos.toByteArray(), Charsets.UTF_8);
    logger.info("Calling URL API: {} returns: {}", url, return_);
    conn.disconnect();
    return return_;
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
origin: Netflix/Priam

  public static String fetchData(String url) {
    DataInputStream responseStream = null;
    try {
      HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
      conn.setConnectTimeout(1000);
      conn.setReadTimeout(10000);
      conn.setRequestMethod("GET");
      if (conn.getResponseCode() != 200)
        throw new RuntimeException("Unable to get data for URL " + url);

      byte[] b = new byte[2048];
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      responseStream = new DataInputStream((FilterInputStream) conn.getContent());
      int c = 0;
      while ((c = responseStream.read(b, 0, b.length)) != -1) bos.write(b, 0, c);
      String return_ = new String(bos.toByteArray(), Charsets.UTF_8);
      logger.info("Calling URL API: {} returns: {}", url, return_);
      conn.disconnect();
      return return_;
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    } finally {
      try {
        if (responseStream != null) responseStream.close();
      } catch (Exception e) {
        logger.warn("Failed to close response stream from priam", e);
      }
    }
  }
}
origin: eclipse-vertx/vert.x

public static JsonObject getContent() throws IOException {
 URL url = new URL("http://localhost:8080");
 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 conn.connect();
 InputStreamReader in = new InputStreamReader((InputStream) conn.getContent());
 BufferedReader buff = new BufferedReader(in);
 String line;
 StringBuilder builder = new StringBuilder();
 do {
  line = buff.readLine();
  builder.append(line).append("\n");
 } while (line != null);
 buff.close();
 return new JsonObject(builder.toString());
}
origin: openmrs/openmrs-core

/**
 * Tests the connection to the specified URL
 *
 * @param urlString the url to test
 * @return true if a connection a established otherwise false
 */
protected static boolean testConnection(String urlString) {
  try {
    HttpURLConnection urlConnect = (HttpURLConnection) new URL(urlString).openConnection();
    //wait for 15sec
    urlConnect.setConnectTimeout(15000);
    urlConnect.setUseCaches(false);
    //trying to retrieve data from the source. If there
    //is no connection, this line will fail
    urlConnect.getContent();
    return true;
  }
  catch (IOException e) {
    if (log.isDebugEnabled()) {
      log.debug("Error generated:", e);
    }
  }
  
  return false;
}

origin: apache/pdfbox

try (InputStream in = (InputStream) httpConnection.getContent())
origin: io.vertx/vertx-core

public static JsonObject getContent() throws IOException {
 URL url = new URL("http://localhost:8080");
 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 conn.connect();
 InputStreamReader in = new InputStreamReader((InputStream) conn.getContent());
 BufferedReader buff = new BufferedReader(in);
 String line;
 StringBuilder builder = new StringBuilder();
 do {
  line = buff.readLine();
  builder.append(line).append("\n");
 } while (line != null);
 buff.close();
 return new JsonObject(builder.toString());
}
origin: com.squareup.okhttp/okhttp-urlconnection

@SuppressWarnings("unchecked") // Spec does not generify
@Override public Object getContent(Class[] types) throws IOException {
 return delegate.getContent(types);
}
origin: stevensouza/automon

public int urlWithConnection(String urlString) throws IOException {
  URL url = new URL(urlString);
  HttpURLConnection connection = (HttpURLConnection)url.openConnection();
  connection.setRequestMethod("GET");
  connection.connect();
  connection.getContent();
  return connection.getResponseCode();
}
origin: jcifs/jcifs

public Object getContent() throws IOException {
  try {
    handshake();
  } catch (IOException ex) { }
  return connection.getContent();
}
origin: com.jaeksoft/jcifs-krb5-jdk7

public Object getContent() throws IOException {
  try {
    handshake();
  } catch (IOException ex) { }
  return connection.getContent();
}
origin: jcifs/jcifs

public Object getContent(Class[] classes) throws IOException {
  try {
    handshake();
  } catch (IOException ex) { }
  return connection.getContent(classes);
}
origin: org.codelibs/jcifs

@Override
public Object getContent ( Class[] classes ) throws IOException {
  handshake();
  return this.connection.getContent(classes);
}
origin: AgNO3/jcifs-ng

@Override
public Object getContent () throws IOException {
  handshake();
  return this.connection.getContent();
}
origin: itext/itext7

static InputStream getHttpResponse(URL urlt) throws IOException {
  HttpURLConnection con = (HttpURLConnection)urlt.openConnection();
  if (con.getResponseCode() / 100 != 2) {
    throw new PdfException(PdfException.InvalidHttpResponse1).setMessageParams(con.getResponseCode());
  }
  return (InputStream) con.getContent();
}
java.netHttpURLConnectiongetContent

Javadoc

Returns the encoding used to transmit the response body over the network. This is null or "identity" if the content was not encoded, or "gzip" if the body was gzip compressed. Most callers will be more interested in the #getContentType(), which may also include the content's character encoding.

Popular methods of HttpURLConnection

  • getInputStream
  • getResponseCode
    Returns the response code returned by the remote HTTP server.
  • setRequestMethod
    Sets the request command which will be sent to the remote HTTP server. This method can only be calle
  • setRequestProperty
  • setDoOutput
  • getOutputStream
  • disconnect
    Releases this connection so that its resources may be either reused or closed. Unlike other Java imp
  • setConnectTimeout
  • connect
  • setReadTimeout
  • getErrorStream
    Returns an input stream from the server in the case of an error such as the requested file has not b
  • setDoInput
  • getErrorStream,
  • setDoInput,
  • getResponseMessage,
  • getHeaderField,
  • setUseCaches,
  • setInstanceFollowRedirects,
  • getHeaderFields,
  • addRequestProperty,
  • getContentLength,
  • getURL

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • putExtra (Intent)
  • runOnUiThread (Activity)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Path (java.nio.file)
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JComboBox (javax.swing)
  • JLabel (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now