{{>licenseInfo}} package {{invokerPackage}}.request; import com.android.volley.AuthFailureError; import com.android.volley.VolleyLog; import com.fht360.fht.volley.RestfulRequest.FHTCallback; import com.fht360.fht.volley.base.AuthenticatedRestfulRequest; import org.apache.http.HttpEntity; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; public class PatchRequest extends AuthenticatedRestfulRequest { HttpEntity entity; String contentType; Map apiHeaders; public PatchRequest(String url, Map apiHeaders, String contentType, HttpEntity entity, FHTCallback callback) { super(Method.PATCH, url, false, callback); this.entity = entity; this.contentType = contentType; this.apiHeaders = apiHeaders; } @Override public String getBodyContentType() { if(this.contentType!=null){ return this.contentType; } if(entity == null) { return null; } return entity.getContentType().getValue(); } @Override public byte[] getBody() throws AuthFailureError { if(entity == null) { return null; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { entity.writeTo(bos); } catch (IOException e) { VolleyLog.e("IOException writing to ByteArrayOutputStream"); } return bos.toByteArray(); } /* (non-Javadoc) * @see com.android.volley.Request#getHeaders() */ @Override public Map getHeaders() throws AuthFailureError { Map headers = super.getHeaders(); if (headers == null || headers.equals(Collections.emptyMap())) { headers = new HashMap(); } if (apiHeaders != null && !apiHeaders.equals(Collections.emptyMap())) { headers.putAll(apiHeaders); } if(contentType != null) { headers.put("Content-Type", contentType); } return headers; } }