/** * If passed httpMethod is of type HttpPost then obtain its entity. If the entity has an enclosing * File then delete it by invoking this method after the request has completed. The entity will * have an enclosing File only if it was too huge to fit into memory. * * @see #writeRequestBodyToOutputStream(ClientRequest) * @param httpMethod - the httpMethod to clean up. */ protected void cleanUpAfterExecute(final HttpRequestBase httpMethod) { if (httpMethod != null && httpMethod instanceof HttpPost) { HttpPost postMethod = (HttpPost) httpMethod; HttpEntity entity = postMethod.getEntity(); if (entity != null && entity instanceof FileExposingFileEntity) { File tempRequestFile = ((FileExposingFileEntity) entity).getFile(); try { boolean isDeleted = tempRequestFile.delete(); if (!isDeleted) { handleFileNotDeletedError(tempRequestFile, null); } } catch (Exception ex) { handleFileNotDeletedError(tempRequestFile, ex); } } } }