Android Open Source - RadioRake File Handler






From Project

Back to project page RadioRake.

License

The source code is released under:

GNU General Public License

If you think the Android project RadioRake 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.asp.radiorake.filehandling;
/*from   www. j  a v a 2 s  .  c  o m*/
import android.os.Environment;
import android.util.Log;

import org.apache.http.util.ByteArrayBuffer;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public abstract class FileHandler {
    private static final String TAG = "com.asp.radiorake.filehandling.FileHandler";

    public static String getFile(String plsUrl, String basePath) {
        //String path = String.format("%s/data/com.statichiss/", basePath);  //put the downloaded file here
        String fileName = String.format("%s%s", basePath, parseFileName(plsUrl));
        File file = new File(fileName);

        try {
            URL url = new URL(plsUrl);

            URLConnection urlConnection = url.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);

            // Read bytes to the Buffer until there inputStream nothing more to read(-1).
            ByteArrayBuffer baf = new ByteArrayBuffer(50);
            int current;
            while ((current = bufferedInputStream.read()) != -1) {
                baf.append((byte) current);
            }

            /* Convert the Bytes read to a String. */
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(baf.toByteArray());
            fos.close();

        } catch (IOException e) {
            Log.e(TAG, "Error occurred attempting to download: " + plsUrl, e);
        }

        return fileName;
    }

    private static String parseFileName(String plsUrl) {
        StringBuilder filename = new StringBuilder();
        int position = plsUrl.lastIndexOf("/");
        filename.append("temp_");
        filename.append(plsUrl.substring(position + 1));
        return filename.toString();
    }

    public static String[] getListOfRecordings(String appName) {
        File recFolder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + appName);
        return recFolder.list(new FilenameFilter() {
            public boolean accept(File file, String name) {
                return name.endsWith("mp3");
            }
        });
    }
}




Java Source Code List

com.asp.radiorake.AddNewScheduledRecordingActivity.java
com.asp.radiorake.AlarmHelper.java
com.asp.radiorake.CallReceiver.java
com.asp.radiorake.ConfirmDetailsActivity.java
com.asp.radiorake.DatabaseHelper.java
com.asp.radiorake.DatePickerFragment.java
com.asp.radiorake.LastPlayedFile.java
com.asp.radiorake.ListScheduledRecordingsActivity.java
com.asp.radiorake.NotificationHelper.java
com.asp.radiorake.PlayerService.java
com.asp.radiorake.PlayingFile.java
com.asp.radiorake.RadioActivity.java
com.asp.radiorake.RadioApplication.java
com.asp.radiorake.RadioDetails.java
com.asp.radiorake.RebootBroadcastReceiver.java
com.asp.radiorake.RecordingsActivity.java
com.asp.radiorake.RecordioBaseActivity.java
com.asp.radiorake.RemoteControlReceiver.java
com.asp.radiorake.ScheduledRecordingsCursorAdaptor.java
com.asp.radiorake.TimePickerFragment.java
com.asp.radiorake.filehandling.FileHandler.java
com.asp.radiorake.filehandling.M3uHandler.java
com.asp.radiorake.filehandling.PlsHandler.java
com.asp.radiorake.recording.RecorderService.java
com.asp.radiorake.recording.RecordingBroadcastReceiver.java
com.asp.radiorake.utils.DateUtils.java
com.asp.radiorake.utils.StringUtils.java