Android Open Source - WifiAlbum File Handler






From Project

Back to project page WifiAlbum.

License

The source code is released under:

MIT License

If you think the Android project WifiAlbum 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 in.zerob13.android.wifialbum.httpserver;
// w ww .  j a  v  a 2  s.  c  om
import android.content.Context;
import android.os.Debug;
import android.util.Log;
import android.webkit.MimeTypeMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.entity.FileEntity;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import in.zerob13.android.wifialbum.utils.Utils;

/**
 * Created by zerob13 on 14-9-16.
 */
public class FileHandler implements HttpRequestHandler {

    private Context context = null;

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

    @Override
    public void handle(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
//        HttpParams params = httpRequest.getParams();
//        httpResponse
        Map<String, String> parames = Utils.getParametersFromUrl(httpRequest.getRequestLine().getUri());
        Log.e("zerob13 test", String.valueOf(parames.size()));
        Log.e("zerob13 test", parames.get("img"));
        File imgFile = new File(parames.get("img"));
        String filePath = parames.get("img");
        String type="image/jpeg";
        String extension = MimeTypeMap.getFileExtensionFromUrl(filePath);
        if (extension != null){
            MimeTypeMap mime = MimeTypeMap.getSingleton();
            type = mime.getMimeTypeFromExtension(extension);
        }

        HttpEntity entity = new FileEntity(imgFile,type) {

        };
//        response.setHeader("Content-Type", "text/html");
        httpResponse.setEntity(entity);
    }
}




Java Source Code List

in.zerob13.android.wifialbum.ApplicationTest.java
in.zerob13.android.wifialbum.WifiActivity.java
in.zerob13.android.wifialbum.httpserver.AssetsHandler.java
in.zerob13.android.wifialbum.httpserver.FileHandler.java
in.zerob13.android.wifialbum.httpserver.HomeCommandHandler.java
in.zerob13.android.wifialbum.httpserver.WebServerService.java
in.zerob13.android.wifialbum.httpserver.WebServer.java
in.zerob13.android.wifialbum.utils.Utils.java