content: package com.freecoders.photobook.network;
  
  import android.util.Log;
  
  import com.android.volley.AuthFailureError;
  import com.android.volley.NetworkResponse;
  import com.android.volley.Request;
  import com.android.volley.Response;
  import com.android.volley.toolbox.HttpHeaderParser;
  import com.freecoders.photobook.common.Constants;
  
  import java.io.UnsupportedEncodingException;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * Created by Alex on 2014-11-27.
   */
  public class StringRequest extends Request<String> {
      private final Response.Listener<String> mListener;
      private static final String PROTOCOL_CHARSET = "utf-8";
      private static final String PROTOCOL_CONTENT_TYPE =
              String.format("application/json; charset=%s", PROTOCOL_CHARSET);
      private String mRequestBody;
      private HashMap<String, String> mRequestHeaders;
  
      /**
       * Creates a new request with the given method.
       *
       * @param method the request {@link Method} to use
       * @param url URL to fetch the string at
       * @param listener Listener to receive the String response
       * @param errorListener Error listener, or null to ignore errors
       */
      public StringRequest(int method, String url, String requestBody,
                           HashMap<String, String> requestHeaders,
                           Response.Listener<String> listener,
                           Response.ErrorListener errorListener) {
          super(method, url, errorListener);
          this.mRequestBody = requestBody;
          this.mRequestHeaders = requestHeaders;
          mListener = listener;
      }
  
      @Override
      public byte[] getBody() {
          try {
              return mRequestBody == null ? null : mRequestBody.getBytes(PROTOCOL_CHARSET);
          } catch (UnsupportedEncodingException uee) {
              return null;
          }
      }
  
      @Override
      public String getBodyContentType() {
          return PROTOCOL_CONTENT_TYPE;
      }
  
      @Override
      public Map<String, String> getHeaders() {
          return ((mRequestHeaders == null) ? Collections.<String, String>emptyMap() : mRequestHeaders);
      }
  
      @Override
      protected void deliverResponse(String response) {
          mListener.onResponse(response);
      }
      @Override
      protected Response<String> parseNetworkResponse(NetworkResponse response) {
          String parsed;
          try {
              parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
          } catch (UnsupportedEncodingException e) {
              parsed = new String(response.data);
          }
          return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
      }
  
      @Override
      protected com.android.volley.VolleyError parseNetworkError(com.android.volley.VolleyError volleyError){
          return volleyError;
      }
  }