Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

In this page you can find the example usage for java.lang RuntimeException RuntimeException.

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:SpecificMethodInfoDemo.java

/**
 * Demo method./*from   w  w  w  .  jav a  2s . co m*/
 * 
 * @param args
 *          Command line arguments.
 * 
 * @throws RuntimeException
 *           If there is a reflection problem.
 */
public static void main(final String[] args) {
    final Method byteValueMeth;
    final Method waitMeth;
    final Method waitDetailMeth;

    try {
        byteValueMeth = Number.class.getMethod("byteValue", null);
        waitMeth = Number.class.getMethod("wait", new Class[] {});
        waitDetailMeth = Number.class.getMethod("wait", new Class[] { long.class, int.class });
    } catch (final NoSuchMethodException ex) {
        throw new RuntimeException(ex);
    }

    System.out.println("byteValueMeth = " + byteValueMeth.toString());
    System.out.println("waitMeth = " + waitMeth.toString());
    System.out.println("waitDetailMeth = " + waitDetailMeth.toString());
}

From source file:Main.java

public static void main(String[] args) {
    TemporalQuery<Integer> daysBeforeChristmas = new TemporalQuery<Integer>() {

        public int daysTilChristmas(int acc, Temporal temporal) {
            int month = temporal.get(ChronoField.MONTH_OF_YEAR);
            int day = temporal.get(ChronoField.DAY_OF_MONTH);
            int max = temporal.with(TemporalAdjusters.lastDayOfMonth()).get(ChronoField.DAY_OF_MONTH);
            if (month == 12 && day <= 25)
                return acc + (25 - day);
            return daysTilChristmas(acc + (max - day + 1),
                    temporal.with(TemporalAdjusters.firstDayOfNextMonth()));
        }/*from  w  w  w  .  j a va 2 s.c o  m*/

        @Override
        public Integer queryFrom(TemporalAccessor temporal) {
            if (!(temporal instanceof Temporal))
                throw new RuntimeException("Temporal accessor must be of type Temporal");
            return daysTilChristmas(0, (Temporal) temporal);
        }
    };

    System.out.println(LocalDate.of(2013, 12, 26).query(daysBeforeChristmas)); // 364
    System.out.println(LocalDate.of(2013, 12, 23).query(daysBeforeChristmas)); // 2
    System.out.println(LocalDate.of(2013, 12, 25).query(daysBeforeChristmas)); // 0
    System.out.println(ZonedDateTime.of(2013, 12, 1, 11, 0, 13, 938282, ZoneId.of("America/Los_Angeles"))
            .query(daysBeforeChristmas)); // 24
}

From source file:com.rest.samples.getImagePrintJPanel.java

public static void main(String[] args) {
    // TODO code application logic here
    String url = "https://api.adorable.io/avatars/eyes5";
    try {/*w ww  . j a  v a2s .co  m*/
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet getMethod = new HttpGet(url);
        getMethod.addHeader("accept", "application/png");
        HttpResponse res = hc.execute(getMethod);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        InputStream is = res.getEntity().getContent();

        Image image = ImageIO.read(is);
        JFrame frame = new JFrame();
        JLabel label = new JLabel(new ImageIcon(image));
        frame.getContentPane().add(label, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.rest.samples.getImage.java

public static void main(String[] args) {
    // TODO code application logic here
    String url = "https://api.adorable.io/avatars/eyes1";
    try {/*  ww  w.  j  a v  a2s. c  o  m*/
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet getMethod = new HttpGet(url);
        getMethod.addHeader("accept", "application/png");
        HttpResponse res = hc.execute(getMethod);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        InputStream is = res.getEntity().getContent();

        OutputStream os = new FileOutputStream(new File("img.png"));
        int read = 0;
        byte[] bytes = new byte[2048];
        while ((read = is.read(bytes)) != -1) {
            os.write(bytes, 0, read);
        }
        is.close();
        os.close();
    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:httpclientsample.HttpClientSample.java

/**
 * @param args the command line arguments
 *///  w  w w . j a v  a 2 s .c o  m
public static void main(String[] args) throws IOException, JSONException {
    /** METHOD GET EXAMPLE **/
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getRequest = new HttpGet("http://localhost:8000/test/api?id=100");
    getRequest.addHeader("accept", "application/json");

    HttpResponse response = httpClient.execute(getRequest);

    if (response.getStatusLine().getStatusCode() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
    }

    InputStreamReader isr = new InputStreamReader((response.getEntity().getContent()));
    BufferedReader br = new BufferedReader(isr);

    String output;
    System.out.println("Response:\n");

    while ((output = br.readLine()) != null) {
        JSONObject jsonObj = new JSONObject(output);
        System.out.println("json id : " + jsonObj.get("id"));
    }

    httpClient.getConnectionManager().shutdown();
}

From source file:com.rest.samples.getReportFromJasperServer.java

public static void main(String[] args) {
    // TODO code application logic here
    String url = "http://username:password@10.49.28.3:8081/jasperserver/rest_v2/reports/Reportes/vencimientos.pdf?feini=2016-09-30&fefin=2016-09-30";
    try {//from  ww w  .  j a va2  s .c om
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet getMethod = new HttpGet(url);
        getMethod.addHeader("accept", "application/pdf");
        HttpResponse res = hc.execute(getMethod);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        InputStream is = res.getEntity().getContent();
        OutputStream os = new FileOutputStream(new File("vencimientos.pdf"));
        int read = 0;
        byte[] bytes = new byte[2048];

        while ((read = is.read(bytes)) != -1) {
            os.write(bytes, 0, read);
        }
        is.close();
        os.close();

        if (Desktop.isDesktopSupported()) {
            File pdfFile = new File("vencimientos.pdf");
            Desktop.getDesktop().open(pdfFile);
        }

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.sm.store.server.RemoteReplicaServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-configPath", "-start" };
    String[] defaults = new String[] { "./config", "true" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[0];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }//from w  ww.ja  va 2 s  .  c om
    //make sure path is in proper format
    configPath = getPath(configPath);
    boolean start = Boolean.valueOf(paras[1]);
    logger.info("read stores.xml from " + configPath);
    BuildRemoteConfig bsc = new BuildRemoteConfig(configPath + "/stores.xml");
    RemoteStoreServer cs = new RemoteStoreServer(bsc.build());
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.toString());
        cs.startServer();
    } else
        logger.warn("server is staged and wait to be started");
    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getRemoteStore(store));
    }
    list.add(cs);
    JmxService jms = new JmxService(list);
}

From source file:jlibs.examples.jdbc.DB.java

public static void main(String[] args) throws Exception {
    try {/*from  w  w  w . j  a  va2 s  .c om*/
        assert false;
        throw new RuntimeException("assertions are not enabled");
    } catch (AssertionError ignore) {
        // ignore
    }

    EMPLOYEES.delete();
    assert EMPLOYEES.all().size() == 0;

    Employee emp = new Employee();
    emp.id = 1;
    emp.setFirstName("santhosh");
    emp.setLastName("kumar");
    emp.setAge(25);
    EMPLOYEES.insert(emp);

    assert EMPLOYEES.all().size() == 1;
    emp.setAge(20);
    EMPLOYEES.update(emp);
    assert EMPLOYEES.all().get(0).getAge() == 20;

    try {
        JDBC.run(new Transaction<Object>() {
            @Override
            public Object run(Connection con) throws SQLException {
                Employee emp = new Employee();
                emp.id = 2;
                emp.setFirstName("santhosh");
                emp.setLastName("kumar");
                emp.setAge(25);
                EMPLOYEES.insert(emp);

                emp.id = 3;
                EMPLOYEES.insert(emp);

                assert EMPLOYEES.all().size() == 3;
                //                    assert table.findOlderEmployees(1).size()==2;
                throw new RuntimeException();
            }
        });
    } catch (RuntimeException ignore) {
        // ignore
    }
    //        assert table.findOlderEmployees(1).size()==0;
    System.out.println(EMPLOYEES.all().size());
    assert EMPLOYEES.all().size() == 1;

    emp.setAge(10);
    EMPLOYEES.upsert(emp);
    assert EMPLOYEES.first("where id=?", emp.id).getAge() == 10;
    emp.id = -1;
    emp.setLastName("KUMAR");
    EMPLOYEES.upsert(emp);
    assert EMPLOYEES.first("where last_name=?", "KUMAR") != null;
    assert EMPLOYEES.all().size() == 2;

    List<Employee> list = EMPLOYEES.all();
    list.get(0).setAge(29);
    EMPLOYEES.update(list.get(0));
    EMPLOYEES.delete(list.get(0));
    //        List<Employee> list = table.findYoungEmployees(50);
    //        Employee emp1 = EMPLOYEES.get(1);
}

From source file:com.sm.store.server.netty.RemoteScan4ReplicaServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-configPath", "-start" };
    String[] defaults = new String[] { "./config", "true" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[0];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }//from  www  .  j  a  v  a2s  .  c  om
    //make sure path is in proper format
    configPath = getPath(configPath);
    boolean start = Boolean.valueOf(paras[1]);
    logger.info("read stores.xml from " + configPath);
    BuildRemoteConfig bsc = new BuildRemoteConfig(configPath + "/stores.xml");
    Scan4RemoteServer cs = new Scan4RemoteServer(bsc.build());
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.toString());
        cs.startServer();
    } else
        logger.warn("server is staged and wait to be started");
    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getRemoteStore(store));
    }
    // add additional name into list for Scan4RemoteServer
    list.add(cs);
    stores.add("Scan4RemoteServer");
    JmxService jms = new JmxService(list, stores);
}

From source file:com.sm.store.server.grizzly.RemoteScan4ReplicaServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-configPath", "-start" };
    String[] defaults = new String[] { "./config", "true" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[0];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }/*  www.  j a  v  a2  s  .c o m*/
    //make sure path is in proper format
    configPath = getPath(configPath);
    boolean start = Boolean.valueOf(paras[1]);
    logger.info("read stores.xml from " + configPath);
    BuildRemoteConfig bsc = new BuildRemoteConfig(configPath + "/stores.xml");
    GZScan4RemoteServer cs = new GZScan4RemoteServer(bsc.build());
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.toString());
        cs.startServer();
    } else
        logger.warn("server is staged and wait to be started");
    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getRemoteStore(store));
    }
    // add additional name into list for Scan4RemoteServer
    list.add(cs);
    stores.add("Scan4RemoteServer");
    JmxService jms = new JmxService(list, stores);
}