Skip to content

Instantly share code, notes, and snippets.

@bsphere
Last active December 27, 2015 12:09
Show Gist options
  • Save bsphere/7324002 to your computer and use it in GitHub Desktop.
Save bsphere/7324002 to your computer and use it in GitHub Desktop.

Revisions

  1. bsphere revised this gist Nov 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MyHTTPClient.java
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ public String getString() throws IOException {

    String line;

    while ((line = reader.readLine() != null) {
    while ((line = reader.readLine()) != null) {
    out.append(line);
    }

  2. bsphere revised this gist Nov 5, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions MyHTTPClient.java
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@ public MyHTTPClient(URL url) {
    public String getString() throws IOException {
    HTTPUrlConnection urlConnection = null;

    URL url = new URL(mUrl, "/string");

    try {
    urlConnection = (HTTPUrlConnection) url.openConnection();

  3. bsphere revised this gist Nov 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MyHTTPClient.java
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ public MyHTTPClient(URL url) {
    mUrl = url;
    }

    public String getSomething() throws IOException {
    public String getString() throws IOException {
    HTTPUrlConnection urlConnection = null;

    try {
  4. bsphere created this gist Nov 5, 2013.
    32 changes: 32 additions & 0 deletions MyHTTPClient.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    public class MyHTTPClient {
    private URL mUrl;
    public MyHTTPClient(URL url) {
    mUrl = url;
    }

    public String getSomething() throws IOException {
    HTTPUrlConnection urlConnection = null;

    try {
    urlConnection = (HTTPUrlConnection) url.openConnection();

    InputStream in = urlConnection.getInputStream();

    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder out = new StringBuilder();

    String line;

    while ((line = reader.readLine() != null) {
    out.append(line);
    }

    return out.toString();

    } finally {
    if (urlConnection != null) urlConnection.disconnect();
    }

    return null;
    }
    }