Example usage for org.apache.http.protocol HTTP OCTET_STREAM_TYPE

List of usage examples for org.apache.http.protocol HTTP OCTET_STREAM_TYPE

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP OCTET_STREAM_TYPE.

Prototype

String OCTET_STREAM_TYPE

To view the source code for org.apache.http.protocol HTTP OCTET_STREAM_TYPE.

Click Source Link

Usage

From source file:com.facebook.stetho.dumpapp.StreamingDumpappHandler.java

@Override
protected HttpEntity getResponseEntity(HttpRequest request, InputStream bufferedInput, HttpResponse response)
        throws IOException {
    DumpappHttpEntity entity = new DumpappHttpEntity(request, getDumper(), bufferedInput);
    entity.setChunked(true);//  www  .  j  a va2s .  co  m
    entity.setContentType(HTTP.OCTET_STREAM_TYPE);
    return entity;
}

From source file:com.facebook.stetho.dumpapp.RawDumpappHandler.java

private static HttpEntity createResponseEntity(byte[] data) {
    ByteArrayEntity entity = new ByteArrayEntity(data);
    if (isProbablyBinaryData(data)) {
        entity.setContentType(HTTP.OCTET_STREAM_TYPE);
    } else {/*from  w  w w . j av a 2  s . c  o  m*/
        entity.setContentType(HTTP.PLAIN_TEXT_TYPE);
    }
    return entity;
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.RequestProtocolCompliance.java

private void addContentTypeHeaderIfMissing(HttpEntityEnclosingRequest request) {
    if (request.getEntity().getContentType() == null) {
        ((AbstractHttpEntity) request.getEntity()).setContentType(HTTP.OCTET_STREAM_TYPE);
    }/*from www  .ja va2 s .c  o m*/
}

From source file:org.jnegre.android.osmonthego.service.ExportService.java

/**
 * Handle export in the provided background thread
 *///  w w w.  j a  va  2  s.  c om
private void handleOsmExport(boolean includeAddress, boolean includeFixme) {
    //TODO handle empty survey
    //TODO handle bounds around +/-180

    if (!isExternalStorageWritable()) {
        notifyUserOfError();
        return;
    }

    int id = 0;
    double minLat = 200;
    double minLng = 200;
    double maxLat = -200;
    double maxLng = -200;
    StringBuilder builder = new StringBuilder();

    if (includeAddress) {
        Uri uri = AddressTableMetaData.CONTENT_URI;
        Cursor cursor = getContentResolver().query(uri, new String[] { //projection
                AddressTableMetaData.LATITUDE, AddressTableMetaData.LONGITUDE, AddressTableMetaData.NUMBER,
                AddressTableMetaData.STREET }, null, //selection string
                null, //selection args array of strings
                null); //sort order

        if (cursor == null) {
            notifyUserOfError();
            return;
        }

        try {
            int iLat = cursor.getColumnIndex(AddressTableMetaData.LATITUDE);
            int iLong = cursor.getColumnIndex(AddressTableMetaData.LONGITUDE);
            int iNumber = cursor.getColumnIndex(AddressTableMetaData.NUMBER);
            int iStreet = cursor.getColumnIndex(AddressTableMetaData.STREET);

            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                //Gather values
                double lat = cursor.getDouble(iLat);
                double lng = cursor.getDouble(iLong);
                String number = cursor.getString(iNumber);
                String street = cursor.getString(iStreet);

                minLat = Math.min(minLat, lat);
                maxLat = Math.max(maxLat, lat);
                minLng = Math.min(minLng, lng);
                maxLng = Math.max(maxLng, lng);
                builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"")
                        .append(lng).append("\" version=\"1\" action=\"modify\">\n");
                addOsmTag(builder, "addr:housenumber", number);
                addOsmTag(builder, "addr:street", street);
                builder.append("</node>\n");
            }
        } finally {
            cursor.close();
        }
    }

    if (includeFixme) {
        Uri uri = FixmeTableMetaData.CONTENT_URI;
        Cursor cursor = getContentResolver().query(uri, new String[] { //projection
                FixmeTableMetaData.LATITUDE, FixmeTableMetaData.LONGITUDE, FixmeTableMetaData.COMMENT }, null, //selection string
                null, //selection args array of strings
                null); //sort order

        if (cursor == null) {
            notifyUserOfError();
            return;
        }

        try {
            int iLat = cursor.getColumnIndex(FixmeTableMetaData.LATITUDE);
            int iLong = cursor.getColumnIndex(FixmeTableMetaData.LONGITUDE);
            int iComment = cursor.getColumnIndex(FixmeTableMetaData.COMMENT);

            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                //Gather values
                double lat = cursor.getDouble(iLat);
                double lng = cursor.getDouble(iLong);
                String comment = cursor.getString(iComment);

                minLat = Math.min(minLat, lat);
                maxLat = Math.max(maxLat, lat);
                minLng = Math.min(minLng, lng);
                maxLng = Math.max(maxLng, lng);
                builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"")
                        .append(lng).append("\" version=\"1\" action=\"modify\">\n");
                addOsmTag(builder, "fixme", comment);
                builder.append("</node>\n");
            }
        } finally {
            cursor.close();
        }
    }

    try {
        File destinationFile = getDestinationFile();
        destinationFile.getParentFile().mkdirs();
        PrintWriter writer = new PrintWriter(destinationFile, "UTF-8");

        writer.println("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");
        writer.println("<osm version=\"0.6\" generator=\"OsmOnTheGo\">");
        writer.print("<bounds minlat=\"");
        writer.print(minLat - MARGIN);
        writer.print("\" minlon=\"");
        writer.print(minLng - MARGIN);
        writer.print("\" maxlat=\"");
        writer.print(maxLat + MARGIN);
        writer.print("\" maxlon=\"");
        writer.print(maxLng + MARGIN);
        writer.println("\" />");

        writer.println(builder);

        writer.print("</osm>");
        writer.close();

        if (writer.checkError()) {
            notifyUserOfError();
        } else {
            //FIXME i18n the subject and content
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            emailIntent.setType(HTTP.OCTET_STREAM_TYPE);
            //emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"johndoe@exemple.com"});
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OSM On The Go");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "Your last survey.");
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile));
            startActivity(emailIntent);
        }
    } catch (IOException e) {
        Log.e(TAG, "Could not write to file", e);
        notifyUserOfError();
    }

}