Android Open Source - photos Utility






From Project

Back to project page photos.

License

The source code is released under:

MIT License

If you think the Android project photos 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.ericfarraro.sdk.util;
/*  w ww  . ja v  a 2s.c o  m*/
import org.apache.http.HttpConnection;

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

/**
 * Created by Eric on 10/7/2014.
 */
public class Utility {

    /**
     * Helper method to get the bytes at a specified url
     * @param u A representation of the URL, as a string
     * @return The bytes at the given URL
     * @throws IOException
     */
    public static byte[] getBytesForUrl(String u) throws IOException {

        URL url = new URL(u);
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();

        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            InputStream in = connection.getInputStream();

            // check to make sure the resource was found successfully
            if(connection.getResponseCode() != HttpURLConnection.HTTP_OK)
                return null;

            int bytesRead = 0;
            byte[] buffer = new byte[1024];

            while((bytesRead = in.read(buffer)) > 0 ) {
                out.write(buffer, 0, bytesRead);
            }

            out.close();
            return out.toByteArray();
        } finally {
            connection.disconnect();
        }
    }
}




Java Source Code List

com.ericfarraro.photos.ApplicationTest.java
com.ericfarraro.photos.activities.MainActivity.java
com.ericfarraro.photos.activities.PhotoDetailActivity.java
com.ericfarraro.photos.adapters.PhotoGalleryItemListAdapter.java
com.ericfarraro.photos.core.EndlessScrollListener.java
com.ericfarraro.photos.core.ImageDownloader.java
com.ericfarraro.photos.fragments.MainFragment.java
com.ericfarraro.photos.fragments.PhotoDetailFragment.java
com.ericfarraro.photos.singletons.PhotoCache.java
com.ericfarraro.sdk.core.ImageDownloader.java
com.ericfarraro.sdk.data.FlickrPhotoSource.java
com.ericfarraro.sdk.data.PhotoSource.java
com.ericfarraro.sdk.interfaces.ImageDownloadCompleted.java
com.ericfarraro.sdk.interfaces.PhotoListRequestCompleted.java
com.ericfarraro.sdk.interfaces.UrlContentRetrieved.java
com.ericfarraro.sdk.models.Photo.java
com.ericfarraro.sdk.util.UrlFetchTask.java
com.ericfarraro.sdk.util.Utility.java