Example usage for java.io IOException printStackTrace

List of usage examples for java.io IOException printStackTrace

Introduction

In this page you can find the example usage for java.io IOException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.linkedin.pinotdruidbenchmark.DruidThroughput.java

@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    if (args.length != 3 && args.length != 4) {
        System.err.println(/*from  w  ww. j  av  a2  s. c om*/
                "3 or 4 arguments required: QUERY_DIR, RESOURCE_URL, NUM_CLIENTS, TEST_TIME (seconds).");
        return;
    }

    File queryDir = new File(args[0]);
    String resourceUrl = args[1];
    final int numClients = Integer.parseInt(args[2]);
    final long endTime;
    if (args.length == 3) {
        endTime = Long.MAX_VALUE;
    } else {
        endTime = System.currentTimeMillis() + Integer.parseInt(args[3]) * MILLIS_PER_SECOND;
    }

    File[] queryFiles = queryDir.listFiles();
    assert queryFiles != null;
    Arrays.sort(queryFiles);

    final int numQueries = queryFiles.length;
    final HttpPost[] httpPosts = new HttpPost[numQueries];
    for (int i = 0; i < numQueries; i++) {
        HttpPost httpPost = new HttpPost(resourceUrl);
        httpPost.addHeader("content-type", "application/json");
        StringBuilder stringBuilder = new StringBuilder();
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(queryFiles[i]))) {
            int length;
            while ((length = bufferedReader.read(CHAR_BUFFER)) > 0) {
                stringBuilder.append(new String(CHAR_BUFFER, 0, length));
            }
        }
        String query = stringBuilder.toString();
        httpPost.setEntity(new StringEntity(query));
        httpPosts[i] = httpPost;
    }

    final AtomicInteger counter = new AtomicInteger(0);
    final AtomicLong totalResponseTime = new AtomicLong(0L);
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);

    for (int i = 0; i < numClients; i++) {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                    while (System.currentTimeMillis() < endTime) {
                        long startTime = System.currentTimeMillis();
                        CloseableHttpResponse httpResponse = httpClient
                                .execute(httpPosts[RANDOM.nextInt(numQueries)]);
                        httpResponse.close();
                        long responseTime = System.currentTimeMillis() - startTime;
                        counter.getAndIncrement();
                        totalResponseTime.getAndAdd(responseTime);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    executorService.shutdown();

    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() < endTime) {
        Thread.sleep(REPORT_INTERVAL_MILLIS);
        double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND;
        int count = counter.get();
        double avgResponseTime = ((double) totalResponseTime.get()) / count;
        System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: "
                + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms");
    }
}

From source file:com.frostwire.search.tests.KATSearchTest.java

public static void main(String[] args) throws InterruptedException {
    SearchEngine KAT = new SearchEngine(1, "KAT", SearchEnginesSettings.KAT_SEARCH_ENABLED, "kat.cr") {
        @Override//from w w  w .  ja  va2s  . c  o m
        public SearchPerformer getPerformer(long token, String keywords) {
            return new KATSearchPerformer(KAT.getDomainName(), token, keywords, 10000);
        }
    };

    final CountDownLatch latch = new CountDownLatch(1);
    final SearchPerformer performer;
    performer = KAT.getPerformer(1, "public domain");

    Action1 onNextAction = new Action1<List<? extends SearchResult>>() {
        @Override
        public void call(List<? extends SearchResult> searchResults) {
            System.out.println("doOnNext!");
            if (searchResults instanceof List) {
                try {
                    if (!testOnSearchResults((List<KATSearchResult>) searchResults)) {
                        System.out.println("Test failed.");
                    } else {
                        System.out.println("Test passed.");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
                latch.countDown();
            }
        }
    };

    final Observable<List<? extends SearchResult>> observable = performer.observable();
    observable.forEach(onNextAction);
    performer.perform();
    System.out.println("performer.perform()\nWaiting...");
    latch.await();

    //System.out.println("Bye bye");

    /**
     byte[] readAllBytes = Files.readAllBytes(Paths.get("/Users/gubatron/tmp/eztv4.html"));
     String fileStr = new String(readAllBytes,"utf-8");
            
     //Pattern pattern = Pattern.compile(REGEX);
     Pattern pattern = Pattern.compile(HTML_REGEX);
            
     Matcher matcher = pattern.matcher(fileStr);
            
     int found = 0;
     while (matcher.find()) {
     found++;
     System.out.println("\nfound " + found);
     System.out.println("displayname: " + matcher.group("displayname"));
     System.out.println("infohash: " + matcher.group("infohash"));
     System.out.println("torrenturl: " + matcher.group("torrenturl"));
     System.out.println("creationtime: " + matcher.group("creationtime"));
     System.out.println("filesize: " + matcher.group("filesize"));
     System.out.println("===");
     }
     //System.out.println("-done-");
     */
}

From source file:examples.rlogin.java

public static final void main(String[] args) {
    String server, localuser, remoteuser, terminal;
    RLoginClient client;/*from   w w  w  . j a va 2s .  c o m*/

    if (args.length != 4) {
        System.err.println("Usage: rlogin <hostname> <localuser> <remoteuser> <terminal>");
        System.exit(1);
        return; // so compiler can do proper flow control analysis
    }

    client = new RLoginClient();

    server = args[0];
    localuser = args[1];
    remoteuser = args[2];
    terminal = args[3];

    try {
        client.connect(server);
    } catch (IOException e) {
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    try {
        client.rlogin(localuser, remoteuser, terminal);
    } catch (IOException e) {
        try {
            client.disconnect();
        } catch (IOException f) {
        }
        e.printStackTrace();
        System.err.println("rlogin authentication failed.");
        System.exit(1);
    }

    IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out);

    try {
        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    System.exit(0);
}

From source file:edu.harvard.i2b2.Icd9ToSnomedCT.BinResourceFromIcd9ToSnomedCTMap.java

public static void main(String[] args) {

    try {//from ww  w.  j  a  va  2s  .  co  m
        new BinResourceFromIcd9ToSnomedCTMap("/Users/kbw19/Downloads/ICD9CM_SNOMEDCT_map_201512/");
    } catch (IOException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        logger.error(e.getMessage(), e);
    }
}

From source file:de.fatalix.book.importer.CalibriImporter.java

public static void main(String[] args) throws IOException, URISyntaxException, SolrServerException {
    Gson gson = new Gson();
    CalibriImporterConfiguration config = gson.fromJson(args[0], CalibriImporterConfiguration.class);
    File importFolder = new File(config.getImportFolder());
    if (importFolder.isDirectory()) {
        File[] zipFiles = importFolder.listFiles(new FilenameFilter() {

            @Override/*from  w w  w  .  ja  va 2 s . c o  m*/
            public boolean accept(File dir, String name) {
                return name.endsWith(".zip");
            }
        });
        for (File zipFile : zipFiles) {
            try {
                processBooks(zipFile.toPath(), config.getSolrCore(), config.getSolrCore(),
                        config.getBatchSize());
                System.out.println("Processed file " + zipFile.getName());
            } catch (IOException ex) {
                ex.printStackTrace();

            }
        }
    } else {
        System.out.println("Import folder: " + importFolder.getAbsolutePath() + " cannot be read!");
    }
}

From source file:at.ac.tuwien.infosys.util.ImageUtil.java

public static void main(String[] args) {
    try {// w  w w.j  a v  a 2s  . c  o m
        ImageUtil util = new ImageUtil();
        util.workingRepo = "/tmp/builder/";
        util.init();
        Path zip = util.createImage(Config.DEVICE_PLAN, "");
        System.out.println("Got: " + zip);
        util.clean();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:examples.unix.rlogin.java

public static void main(String[] args) {
    String server, localuser, remoteuser, terminal;
    RLoginClient client;/*from   w w w .  j  a v a 2 s .  c o  m*/

    if (args.length != 4) {
        System.err.println("Usage: rlogin <hostname> <localuser> <remoteuser> <terminal>");
        System.exit(1);
        return; // so compiler can do proper flow control analysis
    }

    client = new RLoginClient();

    server = args[0];
    localuser = args[1];
    remoteuser = args[2];
    terminal = args[3];

    try {
        client.connect(server);
    } catch (IOException e) {
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    try {
        client.rlogin(localuser, remoteuser, terminal);
    } catch (IOException e) {
        try {
            client.disconnect();
        } catch (IOException f) {
        }
        e.printStackTrace();
        System.err.println("rlogin authentication failed.");
        System.exit(1);
    }

    IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out);

    try {
        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    System.exit(0);
}

From source file:com.dianping.wed.cache.redis.util.TestDataUtil.java

public static void main(String[] args) {
    // ????//  ww  w.  j ava  2s.  c  om

    //&method=incr&parameterTypes=com.dianping.wed.cache.redis.dto.WeddingRedisKeyDTO&parameters={"category":"justtest","params":["1","2"]}
    List<String> opList = new ArrayList<String>(opAndKey.keySet());
    for (int i = 0; i < 1000; i++) {
        int index = RandomUtils.nextInt(opList.size());
        String op = opList.get(index);
        String key = opAndKey.get(op);
        StringBuilder result = new StringBuilder();
        int params = buildTestUrl(result, op, key);

        String fileName = "/Users/Bob/Desktop/data/data-" + params + ".csv";
        try {
            //kuka.txt
            //kuka.txt
            FileWriter writer = new FileWriter(fileName, true);
            writer.write(result.toString());
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    System.out.println("done");
}

From source file:RSATest.java

public static void main(String[] args) {
    try {/*from   w w w  .  ja  va  2  s .  com*/
        if (args[0].equals("-genkey")) {
            KeyPairGenerator pairgen = KeyPairGenerator.getInstance("RSA");
            SecureRandom random = new SecureRandom();
            pairgen.initialize(KEYSIZE, random);
            KeyPair keyPair = pairgen.generateKeyPair();
            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(args[1]));
            out.writeObject(keyPair.getPublic());
            out.close();
            out = new ObjectOutputStream(new FileOutputStream(args[2]));
            out.writeObject(keyPair.getPrivate());
            out.close();
        } else if (args[0].equals("-encrypt")) {
            KeyGenerator keygen = KeyGenerator.getInstance("AES");
            SecureRandom random = new SecureRandom();
            keygen.init(random);
            SecretKey key = keygen.generateKey();

            // wrap with RSA public key
            ObjectInputStream keyIn = new ObjectInputStream(new FileInputStream(args[3]));
            Key publicKey = (Key) keyIn.readObject();
            keyIn.close();

            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.WRAP_MODE, publicKey);
            byte[] wrappedKey = cipher.wrap(key);
            DataOutputStream out = new DataOutputStream(new FileOutputStream(args[2]));
            out.writeInt(wrappedKey.length);
            out.write(wrappedKey);

            InputStream in = new FileInputStream(args[1]);
            cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            crypt(in, out, cipher);
            in.close();
            out.close();
        } else {
            DataInputStream in = new DataInputStream(new FileInputStream(args[1]));
            int length = in.readInt();
            byte[] wrappedKey = new byte[length];
            in.read(wrappedKey, 0, length);

            // unwrap with RSA private key
            ObjectInputStream keyIn = new ObjectInputStream(new FileInputStream(args[3]));
            Key privateKey = (Key) keyIn.readObject();
            keyIn.close();

            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.UNWRAP_MODE, privateKey);
            Key key = cipher.unwrap(wrappedKey, "AES", Cipher.SECRET_KEY);

            OutputStream out = new FileOutputStream(args[2]);
            cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, key);

            crypt(in, out, cipher);
            in.close();
            out.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.alibaba.jstorm.daemon.supervisor.SandBoxMaker.java

public static void main(String[] args) {
    Map<Object, Object> conf = Utils.readStormConfig();

    conf.put("java.sandbox.enable", Boolean.valueOf(true));

    SandBoxMaker maker = new SandBoxMaker(conf);

    try {//from  w  w  w .  j a v  a 2  s  .  c  om
        System.out.println("sandboxPolicy:" + maker.sandboxPolicy("simple", new HashMap<String, String>()));
    } catch (IOException e) {
        e.printStackTrace();
    }
}