Example usage for java.io IOException getCause

List of usage examples for java.io IOException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.hazelcast.qasonar.utils.WhiteListBuilder.java

private static JsonArray getJsonArrayFromUrl(String propertyFileName) {
    InputStream inputStream = null;
    try {// ww  w . j  a  v  a2 s  .c  o  m
        inputStream = new URL(propertyFileName).openStream();
        String json = IOUtils.toString(inputStream);

        Gson gson = new Gson();
        return gson.fromJson(json, JsonArray.class);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not read whitelist from url " + propertyFileName,
                e.getCause());
    } finally {
        closeQuietly(inputStream);
    }
}

From source file:org.obiba.opal.core.service.security.AbstractKeyStoreService.java

private static void translateAndRethrowKeyStoreIOException(IOException ex) {
    if (ex.getCause() != null && ex.getCause() instanceof UnrecoverableKeyException) {
        throw new KeyProviderSecurityException("Wrong keystore password");
    }/* www.  ja va  2  s  .c o  m*/
    throw new RuntimeException(ex);
}

From source file:eu.verdelhan.acr122urw.MifareUtils.java

/**
 * Reads a Mifare Classic 1K block.// w w  w .  ja  v a2  s . c  o  m
 * @param reader the reader
 * @param access the access
 * @return a string representation of the block data, null if the block can't be read
 */
private static String readMifareClassic1KBlock(MfReaderWriter reader, MfAccess access) throws CardException {
    String data = null;
    try {
        MfBlock block = reader.readBlock(access)[0];
        data = bytesToHexString(block.getData());
    } catch (IOException ioe) {
        if (ioe.getCause() instanceof CardException) {
            throw (CardException) ioe.getCause();
        }
    }
    return data;
}

From source file:eu.verdelhan.acr122urw.MifareUtils.java

/**
 * Writes a Mifare Classic 1K block./*from  w w  w  .j a v  a 2 s .  c  o  m*/
 * @param reader the reader
 * @param access the access
 * @param block the block to be written
 * @return true if the block has been written, false otherwise
 */
private static boolean writeMifareClassic1KBlock(MfReaderWriter reader, MfAccess access, MfBlock block)
        throws CardException {
    boolean written = false;
    try {
        reader.writeBlock(access, block);
        written = true;
    } catch (IOException ioe) {
        if (ioe.getCause() instanceof CardException) {
            throw (CardException) ioe.getCause();
        }
    }
    return written;
}

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

public static ImageDescriptor bufferedToDescriptorOptimized(final BufferedImage image) throws IOException {
    final PipedOutputStream output = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream();
    output.connect(pipedInputStream);/*from w ww.j  ava2  s . co m*/

    try {
        new Thread() {

            @Override
            public void run() {
                try {
                    ChartUtilities.writeBufferedImageAsPNG(output, image, false, 0);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }.start();
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
    }

    ImageData img = new ImageData(pipedInputStream);
    ImageDescriptor descriptor = ImageDescriptor.createFromImageData(img);
    return descriptor;
}

From source file:com.ca.dvs.app.dvs_servlet.misc.FileUtil.java

/**
 * Create A File object from the content uploaded to the servlet
 * <p>/*from   w  ww  .j a  v a  2s  . c o m*/
 * @param uploadedInputStream the stream associated with a POSTed form containing a File argument
 * @param fileDetail the File specification for the uploadedInputStream
 * @return the File locally stored from the uploadedInputStream 
 * @throws Exception (IOException net.lingala.zip4j.exception.ZipException)
 */
public static File getUploadedFile(InputStream uploadedInputStream, FormDataContentDisposition fileDetail)
        throws Exception {

    File uploadedFile = null;
    File tmpDir = null;

    try {

        uploadedFile = File.createTempFile(fileDetail.getFileName(), null);

        FileUtils.copyInputStreamToFile(uploadedInputStream, uploadedFile);

        if (FileUtil.isZipFile(uploadedFile)) {

            tmpDir = Files.createTempDir();
            ZipFile zipFile = new ZipFile(uploadedFile);
            zipFile.extractAll(tmpDir.getAbsolutePath());

            uploadedFile.delete();

            uploadedFile = tmpDir;

        }

    } catch (IOException e) {

        String msg = String.format("Failed to store uploaded file - %s", e.getMessage());

        throw new Exception(msg, e.getCause());

    } catch (net.lingala.zip4j.exception.ZipException e) {

        String msg = String.format("Failed to store uploaded file - %s", e.getMessage());

        throw new Exception(msg, e.getCause());

    }

    return uploadedFile;
}

From source file:org.apache.myfaces.wap.renderkit.RendererUtils.java

/** write attribute */
public static void writeAttribute(String attribute, Object value, ResponseWriter writer) {
    log.debug("attribute " + attribute + ": " + value);

    try {/*from   w  w  w  .ja  v a  2 s .  co  m*/
        if (value != null)
            writer.writeAttribute(attribute, value, null);
    } catch (java.io.IOException ex) {
        log.error("Error write attribute '" + attribute + " value: '" + value + "'", ex.getCause());
    }
}

From source file:MdDetect.java

/**
 * Convenience function to grab STDIN/*from w  w  w .  ja  va  2 s  . co m*/
 *
 * @return strings of lines from STDIN
 */
static List<String> getSysIn() {
    InputStreamReader inputStreamReader = null;
    try {
        // initialize the stream reader
        inputStreamReader = new InputStreamReader(System.in);
        // load it into a buffer
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        // init the out list
        List<String> input = new ArrayList<>();

        String line;
        while (null != ( // iterate lines
        line = bufferedReader.readLine())) {
            input.add(line);
        }

        return input;
    } catch (IOException e) {
        // bail
        throw new RuntimeException(e.getCause());
    } finally {
        if (null != inputStreamReader) {
            IOUtils.closeQuietly(inputStreamReader);
        }
    }
}

From source file:de.fu_berlin.inf.dpp.netbeans.feedback.ErrorLogManager.java

/**
 * Submits an error log (errors-only or full, depending on the user's
 * choice) to our server by wrapping the submission in an
 * IRunnableWithProgress to report feedback of the execution in the active
 * workbench windows status bar./*w ww .j  a va  2 s .  co m*/
 * 
 * 
 * @nonblocking
 * @cancelable
 */
public static void submitErrorLog() {
    // determine which log should be uploaded
    final File errorLog = isFullErrorLogSubmissionAllowed() ? getFullErrorLogFile() : getErrorsOnlyLogFile();

    if (errorLog == null)
        return; // If there is no error-log we cannot sent one

    /*
     * cut off a possible file extension and extend the log name to make it
     * unique, e.g. with the userID and sessionID
     */
    final String logNameExtended = FilenameUtils.getBaseName(errorLog.getName()) + "_"
            + StatisticManagerConfiguration.getUserID() + "_" + mostRecentSessionID;

    new Job("Uploading Error Log...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                uploadErrorLog(logNameExtended, errorLog, monitor);
            } catch (IOException e) {
                String msg = String.format("Couldn't upload file: %s. %s", e.getMessage(),
                        e.getCause() != null ? e.getCause().getMessage() : "");
                log.error(msg);
                return new Status(IStatus.ERROR, ListenerForDocumentSwap.PLUGIN_ID, msg, e);
            } catch (OperationCanceledException e) {
                return Status.CANCEL_STATUS;
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }

    }.schedule();
}

From source file:org.apache.axis2.jaxws.util.WSToolingUtils.java

/**
 * Retrieves the major version number of the WsGen class that we're using
 * //from  ww  w.  j  a  va2 s.  co m
 * @return String
 * 
 */
public static String getWsGenVersion() throws ClassNotFoundException, IOException {

    Class clazz = null;
    try {

        clazz = forName("com.sun.tools.ws.WsGen", false, getContextClassLoader(null));

    } catch (ClassNotFoundException e1) {

        try {

            clazz = forName("com.sun.tools.internal.ws.WsGen", false, getContextClassLoader(null));

        } catch (ClassNotFoundException e2) {
            if (log.isDebugEnabled()) {
                log.debug("Exception thrown from getWsGenVersion: " + e2.getMessage(), e2);
            }
            throw (ClassNotFoundException) e2;
        }
    }

    Properties p = new Properties();

    try {

        p.load(clazz.getResourceAsStream("version.properties"));

    } catch (IOException ioex) {
        if (log.isDebugEnabled()) {
            log.debug("Exception thrown from getWsGenVersion: " + ioex.getMessage(), ioex);

        }
        throw (IOException) ioex.getCause();
    }

    return (p.getProperty("major-version"));
}