Example usage for java.io IOException getStackTrace

List of usage examples for java.io IOException getStackTrace

Introduction

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

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:com.bah.applefox.main.plugins.pageranking.utilities.PRtoFile.java

private static HashMap<String, Double> createMap(String[] args)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    HashMap<String, Double> ret = new HashMap<String, Double>();
    String readTable = args[13] + "Old";

    Scanner scan = AccumuloUtils.connectRead(readTable);

    Iterator<Entry<Key, Value>> itr = scan.iterator();

    while (itr.hasNext()) {
        Entry<Key, Value> temp = itr.next();
        try {/*from   w  w  w.ja v a  2s.  c o  m*/
            Double val = (Double) IngestUtils.deserialize(temp.getValue().get());
            ret.put(temp.getKey().getRow().toString(), val);
            System.out.println("Adding to Map: " + temp.getKey().getRow().toString() + " with rank: " + val);
        } catch (IOException e) {
            if (e.getMessage() != null) {
                log.error(e.getMessage());
            } else {
                log.error(e.getStackTrace());
            }
        } catch (ClassNotFoundException e) {
            if (e.getMessage() != null) {
                log.error(e.getMessage());
            } else {
                log.error(e.getStackTrace());
            }
        }
    }

    Double max = 0.0;

    Collection<Double> values = ret.values();

    ArrayList<Double> tempValues = new ArrayList<Double>();
    tempValues.addAll(values);
    Collections.sort(tempValues);
    Collections.reverse(tempValues);

    max = tempValues.get(0);

    ret.put("[[MAX_PR]]", max);

    return ret;
}

From source file:br.pucminas.ri.jsearch.rest.controller.ApiController.java

private static IndexerResponse performIndex() {
    IndexerResponse res;//from w w  w .j a v  a2 s .c  o m

    try {
        res = Indexer.performIndex();
    } catch (IOException ex) {
        res = new IndexerResponse();
        res.setError(true);
        System.out.println(Arrays.toString(ex.getStackTrace()));
    }

    return res;
}

From source file:com.catalyst.sonar.score.batch.util.FileInstaller.java

/**
 * Copies bytes from an InputStream to an OutputStream.
 * //from   w w w. ja  v a 2s  .  c  o  m
 * @param is
 * @param os
 * @return true if copy is successful, false otherwise.
 */
private static boolean copyStream(final InputStream is, final OutputStream os) {
    logger.debug("copyStream(InputStream is, OutputStream os)");
    boolean success = false;
    try {
        final byte[] buf = new byte[1024];

        int len = 0;
        while ((len = is.read(buf)) > 0) {
            os.write(buf, 0, len);
        }
        is.close();
        os.close();
        success = true;
        logger.debug("returning " + success);
        return success;
    } catch (final IOException e) {
        logger.debug(e.getStackTrace().toString());
    }
    logger.debug("returning " + success);
    return false;
}

From source file:net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImplIT.java

@AfterClass
@Ignore/*from www  . j  av  a  2  s .co m*/
// Clean up the credentialManagerDirectory we created for testing
public static void cleanUp() {

    if (credentialManagerDirectory.exists()) {
        try {
            FileUtils.deleteDirectory(credentialManagerDirectory);
            System.out.println(
                    "Deleting Credential Manager's directory: " + credentialManagerDirectory.getAbsolutePath());
        } catch (IOException e) {
            System.out.println(e.getStackTrace());
        }
    }
}

From source file:com.github.rcaller.util.RCodeUtils.java

public static void addDataFrame(StringBuffer rCode, String name, DataFrame dataFrame) {
    try {//from  w w  w .  j av  a 2s . c  o  m
        File file = File.createTempFile("dataFrame", ".csv");
        CSVFileWriter csvFileWriter = CSVFileWriter.create(file.getAbsolutePath());
        csvFileWriter.writeDataFrameToFile(dataFrame);
        rCode.append(name).append(" <- read.csv(\"").append(file.getAbsolutePath()).append("\")\n");

    } catch (IOException e) {
        Logger.getLogger(RCodeUtils.class.getName()).log(Level.WARNING,
                "Couldn't export data frame to csv-file!", e.getStackTrace());
    }

}

From source file:org.sherlok.utils.SherlokTests.java

public static Map<String, List<JsonAnnotation>> assertEquals(Map<String, List<JsonAnnotation>> expecteds,
        String actualsString, Comparison comparison)
        throws SherlokException, JSONException, JsonProcessingException {

    // parse/*from  w w  w .ja  va  2s .  com*/
    Map<String, List<JsonAnnotation>> actuals = null;
    try {
        actuals = SherlokResult.parse(actualsString).getAnnotations();
    } catch (IOException e) {
        throw new SherlokException("could not parse actual annotations").setObject(actualsString)
                .setDetails(e.getStackTrace());
    }

    // validate
    switch (comparison) {
    case atLeast:
        // For each annotation in expecteds we make sure it exists in
        // actuals
        for (Entry<String, List<JsonAnnotation>> entry : expecteds.entrySet()) {

            String expectedAnnotationClass = entry.getKey();
            List<JsonAnnotation> expectedAnnotations = entry.getValue();

            // Get the corresponding annotations and make sure they exists
            List<JsonAnnotation> actualValues = actuals.get(expectedAnnotationClass);
            if (actualValues == null) {
                throw new SherlokException("could not find expected Annotations of type '"
                        + expectedAnnotationClass + "', could only find Annotations of type '"
                        + join(actuals.keySet(), "', '") + "'", expectedAnnotationClass)//
                                .setDetails(map("expected", expecteds, "actual", actuals));
            }

            for (JsonAnnotation expected : expectedAnnotations) {
                // Find an annotation that has the same begin and end in the
                // actual annotations. Note that two annotations with the
                // same key and same region are not supported by this test.
                JsonAnnotation actual = null;
                for (JsonAnnotation annotation : actualValues) {
                    if (expected.getBegin() == annotation.getBegin()
                            && expected.getEnd() == annotation.getEnd()) {
                        actual = annotation;
                        break;
                    }
                }

                // Make sure that such (begin, end) pair was found
                if (actual == null) {
                    throw new SherlokException("could not find expected annotation " + expectedAnnotationClass
                            + expected.toString(), expected.toString())//
                                    .setDetails(map("expected", expecteds, "actual", actuals));
                }

                // Make sure that each expected properties exist
                Map<String, Object> expectedProperties = expected.getProperties();
                Map<String, Object> actualProperties = actual.getProperties();
                for (Entry<String, Object> expectedProperty : expectedProperties.entrySet()) {
                    Object actualProperty = actualProperties.get(expectedProperty.getKey());

                    // This isn't a proper recursive solution: it means
                    // that sub-properties must be included in both
                    // expected and actual properties. Hence the "at least"
                    // test is not perfect.
                    if (!expectedProperty.getValue().equals(actualProperty)) {
                        throw new SherlokException("actual property '" + actualProperty
                                + "' is not equal to expected property '" + expectedProperty + "'")//
                                        .setDetails(map("expected", expecteds, "actual", actuals));
                    }
                }
            }
        }

        break;

    case exact:// FIXME implement exact comparison
        for (Entry<String, List<JsonAnnotation>> exp : expecteds.entrySet()) {
            String eType = exp.getKey();
            if (!actuals.containsKey(eType)) {
                throw new SherlokException("could not find expected key", eType);

            } else {
                for (JsonAnnotation a : exp.getValue()) {
                    boolean found = false;
                    for (JsonAnnotation sa : actuals.get(eType)) {
                        // FIXME currently it is not recursive
                        if (sa.equals(a)) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new SherlokException("could not find expected annotation", a.toString());
                    }
                }
            }
        }
        break;

    /*-
    // compare 2-ways; give explicit error msg
    for (Entry<String, List<Annotation>> exp : expecteds.entrySet()) {
    if (!systems.values().contains(exp)) {
        throw new SherlokException(map(ERR_NOTFOUND, exp,
                EXPECTED, expecteds, SYSTEM, systems));
    }
    }
    for (List<Annotation> sysAs : systems.values()) {
    for (Annotation sysa : sysAs) {
        if (!expecteds.values().contains(sysa)) {
            throw new SherlokException(map(ERR_UNEXPECTED, sysa,
                    EXPECTED, expecteds, SYSTEM, systems));
        }
    }
    }
    break;
     */
    }
    return actuals;
}

From source file:uk.ac.ucl.chem.ccs.clinicalgui.ClinicalGuiClient.java

private static void loadProperties() {
    String confprop = System.getProperty("uk.ac.ucl.chem.ccs.aheclient.conffile");

    if (confprop != null && !confprop.equals("")) {
        propertiesFile = confprop;/* w ww.  jav  a 2  s  .  com*/
        System.out.println("foo" + propertiesFile);
    } else {
        propertiesFile = "aheclient.properties";
    }

    prop = new Properties();

    try {
        prop.load(new FileInputStream(propertiesFile));
        cat.info("Opened properties file " + propertiesFile);
    } catch (IOException e) {
        cat.error("Couldn't open properties file " + propertiesFile + "!");
        cat.error(e.getMessage());
        cat.debug(e.getStackTrace());
        cat.error("Configure client settings now");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-server", "myproxy.grid-support.ac.uk");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-dn",
                "/C=UK/O=eScience/OU=CLRC/L=DL/CN=host/myproxy.grid-support.ac.uk/E=a.j.richards@dl.ac.uk");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-port", "7512");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-lifetime", "7512");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-un", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-pw", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.ahedavuser", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.ahedavpasswd", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.ahedavserver", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.jobregepr", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.keystore", "aheclient.ks");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.jobfactoryepr", "");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.mpcheck", "false");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.mpwarn", "false");

        //some more
        //proxy location
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.proxyfile", "/tmp/x501");

        //gridftp server
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.gridftpserver", "none");

        //gridftp port
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.gridftpport", "2811");

        //repository location
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.modelrep", "/models");

        //dicom server
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomserver", "none");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomserverport", "none");

        //dicom client
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomclient", "none");
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomclientport", "none");

        //dicom client name
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomclientname", "false");

        //dicom tempdir
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomtmpdir", "/tmp");

        //dicom slices
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.dicomslices", "/tmp");

        //harc-path
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.harcpath", "false");

        //harc-path
        prop.setProperty("uk.ac.ucl.chem.ccs.aheclient.segtool", "/tmp/sg");

    }

    //set HARC client properties from file to system properties
    System.setProperty("harc.client.installpath", prop.getProperty("uk.ac.ucl.chem.ccs.aheclient.harcpath"));
    System.setProperty("harc.client.secure.gsi_proxy_location",
            prop.getProperty("uk.ac.ucl.chem.ccs.aheclient.proxyfile"));
    System.setProperty("ahe.java.version", prop.getProperty("uk.ac.ucl.chem.ccs.aheclient.javaversion"));

    //unlock
    String passwd = null;
    passwd = prop.getProperty("uk.ac.ucl.chem.ccs.aheclient.passwd");
    if (!checkKeystore(passwd)) {
        System.err.println("Can't open keystore");
    }

}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

private static Response executeMethod(HttpMethod httpMethod, String type, String username, String password,
        String url) {//from w ww.  j  ava 2  s. c o  m
    HttpClient client = getClient(url, username, password);
    Response response = null;

    // We set the Heathers
    httpMethod.setDoAuthentication(true);
    httpMethod.addRequestHeader(BONFIRE_ASSERTED_ID_HEADER, username);
    //httpMethod.addRequestHeader(BONFIRE_ASSERTED_ID_HEADER, groups);
    httpMethod.addRequestHeader("Accept", type);
    httpMethod.addRequestHeader("Content-Type", type);

    try {
        int statusCode = client.executeMethod(httpMethod);
        String responsePayload = httpMethod.getResponseBodyAsString();
        response = new Response(statusCode, responsePayload);
    } catch (IOException iOException) {
        System.out.println("ERROR TRYING TO PERFORM GET TO: " + httpMethod.getPath());
        System.out.println("ERROR: " + iOException.getMessage());
        System.out.println("ERROR: " + iOException.getStackTrace());
    } finally {
        httpMethod.releaseConnection();
    }

    return response;
}

From source file:com.jktsoftware.amazondownloader.download.Application.java

public static void downloadObject(IObject objecttodownload, IQueueManager queuemanager) {
    ConsoleProgressBar progressbar = new ConsoleProgressBar();
    System.out.println("Attempting to get object: " + objecttodownload.getObjectKey());
    try {//from w w  w  . ja va2 s. c  o  m
        //create an inputstream object for the download from the repo
        InputStream input = objecttodownload.getObjectContent();
        //create an outputstream for writing the stream to a local file
        OutputStream outStream = new FileOutputStream(objecttodownload.getObjectKey());
        //current bytes read from the repo
        long currentbytes = 0;
        //bytes read within the loop
        int bytesread = 0;
        //print status message to the console
        System.out.println("Starting download of :" + objecttodownload.getObjectKey());
        //progress message variable
        String previousprogress = "";
        //buffer for holding downloaded bytes
        byte[] bytebuffer = new byte[512 * 1024];
        //start downloading file bit by bit
        while ((bytesread = input.read(bytebuffer)) != -1) {
            //write downloaded bytes to the file
            outStream.write(bytebuffer, 0, bytesread);
            //update downloaded byte count
            currentbytes = currentbytes + bytesread;
            //get a text representation of a progress bar
            String newprogress = progressbar.getProgress(currentbytes, objecttodownload.getObjectSize()) + "\r";
            if (!newprogress.contentEquals(previousprogress)) {
                //write progress bar to console
                System.out.print(newprogress);
                previousprogress = newprogress;
            }
        }
        //write progress bar to console
        System.out.println(progressbar.getProgress(currentbytes, objecttodownload.getObjectSize()));
        System.out.println("Object downloaded");
        //close the streams
        input.close();
        outStream.close();
        //update queue with details of downloaded file
        queuemanager.sendReceivedObjectMessageToQueue(objecttodownload.getObjectKey());

    } catch (IOException e) {
        e.printStackTrace();
        //update queue with details of failed file
        queuemanager.sendFailedObjectMessageToQueue(objecttodownload.getObjectKey(),
                e.getStackTrace().toString());
    }
}

From source file:de.ingrid.iplug.csw.dsc.tools.FileUtils.java

/**
 * This function will copy files or directories from one location to another.
 * note that the source and the destination must be mutually exclusive. This 
 * function can not be used to copy a directory to a sub directory of itself.
 * The function will also have problems if the destination files already exist.
 * @param src -- A File object that represents the source for the copy
 * @param dest -- A File object that represnts the destination for the copy.
 * @throws IOException if unable to copy.
 * /*from  w  w w.j av a 2 s.c  o m*/
 * Source: http://www.dreamincode.net/code/snippet1443.htm
 */
public static void copyRecursive(File src, File dest) throws IOException {
    //Check to ensure that the source is valid...
    if (!src.exists()) {
        throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath() + ".");
    } else if (!src.canRead()) { //check to ensure we have rights to the source...
        throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + ".");
    }
    //is this a directory copy?
    if (src.isDirectory()) {
        if (!dest.exists()) { //does the destination already exist?
            //if not we need to make it exist if possible (note this is mkdirs not mkdir)
            if (!dest.mkdirs()) {
                throw new IOException("copyFiles: Could not create direcotry: " + dest.getAbsolutePath() + ".");
            }
        }
        //get a listing of files...
        String list[] = src.list();
        //copy all the files in the list.
        for (int i = 0; i < list.length; i++) {
            File dest1 = new File(dest, list[i]);
            File src1 = new File(src, list[i]);
            copyRecursive(src1, dest1);
        }
    } else {
        //This was not a directory, so lets just copy the file
        FileInputStream fin = null;
        FileOutputStream fout = null;
        byte[] buffer = new byte[4096]; //Buffer 4K at a time (you can change this).
        int bytesRead;
        try {
            //open the files for input and output
            fin = new FileInputStream(src);
            fout = new FileOutputStream(dest);
            //while bytesRead indicates a successful read, lets write...
            while ((bytesRead = fin.read(buffer)) >= 0) {
                fout.write(buffer, 0, bytesRead);
            }
            fin.close();
            fout.close();
            fin = null;
            fout = null;
        } catch (IOException e) { //Error copying file... 
            IOException wrapper = new IOException("copyFiles: Unable to copy file: " + src.getAbsolutePath()
                    + "to" + dest.getAbsolutePath() + ".");
            wrapper.initCause(e);
            wrapper.setStackTrace(e.getStackTrace());
            throw wrapper;
        } finally { //Ensure that the files are closed (if they were open).
            if (fin != null) {
                fin.close();
            }
            if (fout != null) {
                fin.close();
            }
        }
    }
}