Example usage for java.util HashMap getClass

List of usage examples for java.util HashMap getClass

Introduction

In this page you can find the example usage for java.util HashMap getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.melchor629.musicote.Utils.java

public static ArrayList getHashMapFromUrl(String url) {
    //StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    //StrictMode.setThreadPolicy(policy);
    HashMap map = new HashMap();
    try {/* ww  w  . j av  a 2 s .c o m*/
        long time = System.currentTimeMillis();
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpPost = new HttpGet(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        InputStream is = httpEntity.getContent();

        //BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF8"), 8192);
        StringBuilder sb = new StringBuilder();
        byte[] buff = new byte[256];
        int length = is.read(buff);
        sb.append(new String(buff, 0, length));
        while ((length = is.read(buff)) != -1) {
            sb.append(new String(buff, 0, length));
        }
        is.close();
        Log.d("MainActivity", String.format("JSON Downloaded in %dms", System.currentTimeMillis() - time));

        time = System.currentTimeMillis();
        Gson gson = new Gson();
        String s = sb.toString();
        map = gson.fromJson(s, map.getClass());
        Log.d("MainActivity", String.format("JSON parsed in %dms", System.currentTimeMillis() - time));
        return (ArrayList) map.get("canciones");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        Log.e("Utils", "El archivo recibido no es json");
    }
    return null;
}

From source file:com.doitnext.http.router.RestRouterServletTest.java

@Test
public void testHandleStores() throws Exception {
    RestRouterServlet servlet = new RestRouterServlet();
    servlet.setPathPrefix("/sports-api");
    servlet.setRestPackageRoot("com.doitnext.http.router.exampleclasses");
    servlet.setEndpointResolver(endpointResolver);
    servlet.setMethodInvoker(methodInvoker);
    servlet.setErrorHandler(errorHandler);
    servlet.setDynamicEndpointResolver(null);
    servlet.afterPropertiesSet();/*from  w w  w . ja  va2s  . c o m*/

    MockHttpServletRequest request;
    MockHttpServletResponse response;

    Object[][] testCases = { { "GET", "/mocker", "/sports-api/teams/favorites/user01/path/to/resource",
            "city=Atlanta", "application/json; model=hashmap", null, null, "user01", "path/to/resource" }, };

    for (Object[] testCase : testCases) {
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        setUpRequest(testCase, request);
        servlet.handleRequest(request, response);
        String content = response.getContentAsString();
        System.out.println(content);
        Assert.assertEquals(200, response.getStatus());
        HashMap<String, String> t = new HashMap<String, String>();
        @SuppressWarnings("unchecked")
        Map<String, String> returnVal = objectMapper.readValue(content, t.getClass());
        Assert.assertEquals(testCase[7], returnVal.get("userId"));
        Assert.assertEquals(testCase[8], returnVal.get("storePath"));

    }
}

From source file:password.pwm.event.AuditManager.java

private static void sendAsEmail(final PwmApplication pwmApplication, final SessionLabel sessionLabel,
        final AuditRecord record, final String toAddress, final String fromAddress

) throws PwmUnrecoverableException {
    final String subject = PwmConstants.PWM_APP_NAME + " - Audit Event - " + record.getEventCode().toString();

    final StringBuilder body = new StringBuilder();
    final String jsonRecord = JsonUtil.serialize(record);
    HashMap<String, Serializable> mapRecord = new HashMap<>();
    mapRecord = JsonUtil.deserialize(jsonRecord, mapRecord.getClass());

    for (final String key : mapRecord.keySet()) {
        body.append(key);/*from  w  w w . j  a v  a 2 s  .  c  o  m*/
        body.append("=");
        body.append(mapRecord.get(key));
        body.append("\n");
    }

    final EmailItemBean emailItem = new EmailItemBean(toAddress, fromAddress, subject, body.toString(), null);
    final MacroMachine macroMachine = MacroMachine.forNonUserSpecific(pwmApplication, sessionLabel);
    pwmApplication.getEmailQueue().submitEmail(emailItem, null, macroMachine);
}