Android Open Source - NoiseBridge_General Get And Discard Url Task






From Project

Back to project page NoiseBridge_General.

License

The source code is released under:

GPLv3.txt

If you think the Android project NoiseBridge_General listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.metamage.noisegate;
/*w w  w  .  j  ava2s.  co  m*/
import android.os.AsyncTask;

import java.io.InputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;


public final class GetAndDiscardUrlTask extends AsyncTask< Void, Integer, Void >
{
  private static boolean busy;
  
  private String itsUrlString;
  
  URL itsUrl;
  
  Completion itsCompletion;
  
  IOException itsSavedException;
  
  public GetAndDiscardUrlTask( Completion completion, String urlString )
  {
    if ( busy )
    {
      cancel( false );  // no need to interrupt, we never enter doInBackground()
      
      return;
    }
    
    busy = true;
    
    itsCompletion = completion;
    
    itsUrlString = urlString;
  }
  
  protected Void doInBackground( Void... v )
  {
    try
    {
      final URL url = new URL( itsUrlString );
      
      HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
      
      try
      {
        InputStream input = urlConnection.getInputStream();
        
        try
        {
          String connectedHost = urlConnection.getURL().getHost();
          
          if ( !url.getHost().equals( connectedHost ) )
          {
            throw new ProtocolException( "HTTP redirect to " + connectedHost + " not allowed" );
          }
          
          int contentLength = urlConnection.getContentLength();
        }
        finally
        {
          input.close();
        }
      }
      finally
      {
        urlConnection.disconnect();
      }
    }
    catch ( IOException e )
    {
      itsSavedException = e;
    }
    
    return (Void) null;
  }
  
  protected void onProgressUpdate( Integer... params )
  {
  }
  
  protected void onPostExecute( Void v )
  {
    busy = false;
    
    itsCompletion.call( itsSavedException );
  }
}




Java Source Code List

com.loopj.android.http.AsyncHttpClient.java
com.loopj.android.http.AsyncHttpRequest.java
com.loopj.android.http.AsyncHttpResponseHandler.java
com.loopj.android.http.BinaryHttpResponseHandler.java
com.loopj.android.http.JsonHttpResponseHandler.java
com.loopj.android.http.PersistentCookieStore.java
com.loopj.android.http.RequestParams.java
com.loopj.android.http.RetryHandler.java
com.loopj.android.http.SerializableCookie.java
com.loopj.android.http.SimpleMultipartEntity.java
com.loopj.android.http.SyncHttpClient.java
com.metamage.noisegate.Completion.java
com.metamage.noisegate.Data.java
com.metamage.noisegate.F.java
com.metamage.noisegate.GetAndDiscardUrlTask.java
com.metamage.noisegate.Key.java
com.metamage.noisegate.Noisegate.java
com.metamage.noisegate.Teletype.java
com.noysbrij.fragments.DatePickerFragment.java
com.noysbrij.fragments.JSInterface.java
com.noysbrij.fragments.ListViewFragment.java
com.noysbrij.fragments.NBWebViewFragment.java
com.noysbrij.fragments.TicketsArrayAdapter.java
com.noysbrij.fragments.TimePickerFragment.java
com.noysbrij.noisebridgeGeneral.NoiseBridgeGeneral.java
com.noysbrij.noisebridgeGeneral.ReadJson.java
com.noysbrij.noisebridgeGeneral.Ticket.java
com.noysbrij.noisebridgeGeneral.TicketsExpandableListAdapter.java
com.noysbrij.noisebridgeGeneral.Tickets.java