Android Open Source - Realtime-Port-Authority Input Save






From Project

Back to project page Realtime-Port-Authority.

License

The source code is released under:

Apache License

If you think the Android project Realtime-Port-Authority 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 rectangledbmi.com.pittsburghrealtimetracker.handlers;
//www  . j a  v a 2 s .co  m
import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import rectangledbmi.com.pittsburghrealtimetracker.hidden.PortAuthorityAPI;

/**
 * Inspired by http://stackoverflow.com/questions/8986376/how-to-download-xml-file-from-server-and-save-it-in-sd-card
 *
 * Created by epicstar on 1/12/15.
 */
public class InputSave {
    private Context context;

    public InputSave(Context context) {
        this.context = context;
    }

    public void saveFile(String selectedRoute) {
        try {
            File file = new File(context.getFilesDir(), "/lineinfo/" + selectedRoute + ".xml");
            if(!file.exists()) {
                URL url = PortAuthorityAPI.getPatterns(selectedRoute);
                URLConnection conexion = url.openConnection();
                conexion.connect();
                int lengthOfFile = conexion.getContentLength();
                InputStream is = url.openStream();

                FileOutputStream fos = new FileOutputStream(file);
                byte data[] = new byte[1024];
                int count = 0;
                long total = 0;
                int progress = 0;
                while ((count = is.read(data)) != -1) {
                    total += count;
                    int progress_temp = (int) total * 100 / lengthOfFile;
                    if (progress_temp % 10 == 0 && progress != progress_temp) {
                        progress = progress_temp;
                    }
                    fos.write(data, 0, count);
                }
                is.close();
                fos.close();
                Log.i("save_file", selectedRoute + " attempted file saved...");
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}




Java Source Code List

.Globals.java
.PortAuthorityRealtime.java
rectangledbmi.com.pittsburghrealtimetracker.AboutActivity.java
rectangledbmi.com.pittsburghrealtimetracker.ApplicationTest.java
rectangledbmi.com.pittsburghrealtimetracker.BusInformationDialog.java
rectangledbmi.com.pittsburghrealtimetracker.NavigationDrawerFragment.java
rectangledbmi.com.pittsburghrealtimetracker.SelectTransit.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.BusNotRunningException.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.BusSaxHandler.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.BusXMLPullParser.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.InputSave.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.PredictionsXMLPullParser.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.RequestLine.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.RequestPredictions.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.RequestRoutes.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.RequestTask.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.RouteSaxHandler.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.TransitSAXHandler.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.containers.ETAContainer.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.containers.RequestLineContainer.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.extend.CheckableRelativeLayout.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.extend.ColoredArrayAdapter.java
rectangledbmi.com.pittsburghrealtimetracker.handlers.extend.ETAWindowAdapter.java
rectangledbmi.com.pittsburghrealtimetracker.world.Bus.java
rectangledbmi.com.pittsburghrealtimetracker.world.LineInfo.java
rectangledbmi.com.pittsburghrealtimetracker.world.Prediction.java
rectangledbmi.com.pittsburghrealtimetracker.world.Route.java
rectangledbmi.com.pittsburghrealtimetracker.world.TransitStop.java