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:eu.learnpad.core.impl.qm.XwikiCoreFacadeRestResource.java

@Override
public void publish(String questionnairesId, String type, byte[] questionnairesFile) throws LpRestException {
    // Now actually notifying the CP via REST
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/qm/corefacade/publish/%s", DefaultRestResource.REST_URI,
            questionnairesId);/*from  w  ww . j a va 2s.  co m*/

    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM);

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("type", type);
    putMethod.setQueryString(queryString);

    InputStream stream = new ByteArrayInputStream(questionnairesFile);
    RequestEntity requestEntity = new InputStreamRequestEntity(stream);
    putMethod.setRequestEntity(requestEntity);

    try {
        httpClient.executeMethod(putMethod);
    } catch (IOException e) {
        LpRestExceptionXWikiImpl e1 = new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
        throw e1;
    }
}

From source file:cz.incad.kramerius.audio.servlets.ServletAudioHttpRequestForwarder.java

private void forwardData(InputStream input, ServletOutputStream output) {
    try {/*ww w.  j  a  va 2  s  .c  o m*/
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesForwarded;
        while ((bytesForwarded = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesForwarded);
        }
    } catch (IOException ex) {
        if (ex.getCause() != null && ex.getCause() instanceof SocketException
                && (ex.getCause().getMessage().equals(CONNECTION_RESET)
                        || ex.getCause().getMessage().equals(BROKEN_PIPE))) {
            LOGGER.warning("Connection reset probably by client (or by repository)");
        } else {
            if (!"ClientAbortException".equals(ex.getClass().getSimpleName())) {
                LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
            }
        }
    } finally {
        try {
            LOGGER.fine("closing connection to repository");
            input.close();
            //output stream should not be closed here because it is closed by container. 
            //If closed here, for example filters won't be able to write to stream anymore
        } catch (IOException ex1) {
            LOGGER.log(Level.SEVERE, "Failed to close connection to repository", ex1);
        }
    }
}

From source file:cz.incad.Kramerius.audio.AudioHttpRequestForwarder.java

private void forwardData(InputStream input, ServletOutputStream output) {
    try {/*from  ww w  .  j  av a 2  s  .  c o  m*/
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesForwarded;
        while ((bytesForwarded = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesForwarded);
        }
    } catch (IOException ex) {
        if (ex.getCause() != null && ex.getCause() instanceof SocketException
                && (ex.getCause().getMessage().equals(CONNECTION_RESET)
                        || ex.getCause().getMessage().equals(BROKEN_PIPE))) {
            LOGGER.warning("Connection reset probably by client (or by repository)");
        } else {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    } finally {
        try {
            LOGGER.fine("closing connection to repository");
            input.close();
            //output stream should not be closed here because it is closed by container. 
            //If closed here, for example filters won't be able to write to stream anymore
        } catch (IOException ex1) {
            LOGGER.log(Level.SEVERE, "Failed to close connection to repository", ex1);
        }
    }
}

From source file:eu.learnpad.core.impl.or.XwikiCoreFacadeRestResource.java

@Override
public InputStream getModel(String modelSetId, ModelSetType type) throws LpRestException {
    // Now send the package's path to the importer for XWiki
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/or/corefacade/getmodel/%s", DefaultRestResource.REST_URI,
            modelSetId);//from w  ww .java  2  s .co m
    GetMethod getMethod = new GetMethod(uri);
    getMethod.addRequestHeader("Accept", "application/xml");

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("type", type.toString());
    getMethod.setQueryString(queryString);

    InputStream model = null;
    try {
        httpClient.executeMethod(getMethod);
        model = getMethod.getResponseBodyAsStream();
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
    return model;
}

From source file:eu.learnpad.core.impl.or.XwikiCoreFacadeRestResource.java

@Override
public InputStream getExternalKPIs(String modelSetId, String kpisid, KPIsFormat type) throws LpRestException {
    // Now send the package's path to the importer for XWiki
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/or/corefacade/getkpis/%s/%s", DefaultRestResource.REST_URI,
            modelSetId, kpisid);//from  ww  w  .  ja  va2s. c  om
    GetMethod getMethod = new GetMethod(uri);
    getMethod.addRequestHeader("Accept", "application/xml");

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("type", type.toString());
    getMethod.setQueryString(queryString);

    InputStream kpisStream = null;
    try {
        httpClient.executeMethod(getMethod);
        kpisStream = getMethod.getResponseBodyAsStream();
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
    return kpisStream;
}

From source file:org.tangram.components.servlet.ServletRequestParameterAccess.java

/**
 * Weak visibility to avoid direct instanciation.
 *///from ww  w . ja  v  a 2s  .co m
@SuppressWarnings("unchecked")
ServletRequestParameterAccess(HttpServletRequest request, long uploadFileMaxSize) {
    final String reqContentType = request.getContentType();
    LOG.debug("() uploadFileMaxSize={} request.contentType={}", uploadFileMaxSize, reqContentType);
    if (StringUtils.isNotBlank(reqContentType) && reqContentType.startsWith("multipart/form-data")) {
        ServletFileUpload upload = new ServletFileUpload();
        upload.setFileSizeMax(uploadFileMaxSize);
        try {
            for (FileItemIterator itemIterator = upload.getItemIterator(request); itemIterator.hasNext();) {
                FileItemStream item = itemIterator.next();
                String fieldName = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField()) {
                    String[] value = parameterMap.get(item.getFieldName());
                    int i = 0;
                    if (value == null) {
                        value = new String[1];
                    } else {
                        String[] newValue = new String[value.length + 1];
                        System.arraycopy(value, 0, newValue, 0, value.length);
                        i = value.length;
                        value = newValue;
                    } // if
                    value[i] = Streams.asString(stream, "UTF-8");
                    LOG.debug("() request parameter {}='{}'", fieldName, value[0]);
                    parameterMap.put(item.getFieldName(), value);
                } else {
                    try {
                        LOG.debug("() item {} :{}", item.getName(), item.getContentType());
                        final byte[] bytes = IOUtils.toByteArray(stream);
                        if (bytes.length > 0) {
                            originalNames.put(fieldName, item.getName());
                            blobs.put(fieldName, bytes);
                        } // if
                    } catch (IOException ex) {
                        LOG.error("()", ex);
                        if (ex.getCause() instanceof FileUploadBase.FileSizeLimitExceededException) {
                            throw new RuntimeException(ex.getCause().getMessage()); // NOPMD we want to lose parts of our stack trace!
                        } // if
                    } // try/catch
                } // if
            } // for
        } catch (FileUploadException | IOException ex) {
            LOG.error("()", ex);
        } // try/catch
    } else {
        parameterMap = request.getParameterMap();
    } // if
}

From source file:org.apache.hadoop.hbase.util.TestCompressionTest.java

@Test
public void testExceptionCaching() {
    // This test will fail if you run the tests with LZO compression available.
    try {/*from   ww w  . j a v  a  2s .com*/
        CompressionTest.testCompression(Compression.Algorithm.LZO);
        fail(); // always throws
    } catch (IOException e) {
        // there should be a 'cause'.
        assertNotNull(e.getCause());
    }

    // this is testing the caching of the test results.
    try {
        CompressionTest.testCompression(Compression.Algorithm.LZO);
        fail(); // always throws
    } catch (IOException e) {
        // there should be NO cause because it's a direct exception not wrapped
        assertNull(e.getCause());
    }

    assertFalse(CompressionTest.testCompression("LZO"));
}

From source file:uk.ac.ebi.atlas.search.diffanalytics.DiffAnalyticsTSVWriter.java

@Override
public void visit(DiffAnalytics value) {
    try {/*from   w w w .j a  v a  2  s.  co m*/
        write(value);
    } catch (IOException e) {
        throw new VisitorException(e.getMessage(), e.getCause());
    }
}

From source file:net.phamngochai.beefnoodle.ui.DownloadDictionaryActivity.java

private String getDictionaryListFromInternet() {
    String xml = null;// ww w .j a  v  a2  s.com
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(DICTIONARY_LIST_URL);
        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);
    } catch (IOException e) {
        Log.d(TAG, "Exception while loading xml: " + e.getMessage() + ", caused by: " + e.getCause());
        return null;
    }
    Log.d(TAG, xml);
    return xml;
}

From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMFile.java

private Object metadata() throws IOException {
    if (metadata == null && !resolved) {
        try {//from  www.  j  ava 2s  .c  o m
            switch (info) {
            case DIRECTORY_ASSUMED:
                metadata = repo.getDirectoryContent(getPath(), ref);
                info = TypeInfo.DIRECTORY_CONFIRMED;
                resolved = true;
                break;
            case DIRECTORY_CONFIRMED:
                metadata = repo.getDirectoryContent(getPath(), ref);
                resolved = true;
                break;
            case NON_DIRECTORY_CONFIRMED:
                metadata = repo.getFileContent(getPath(), ref);
                resolved = true;
                break;
            case UNRESOLVED:
                try {
                    metadata = repo.getFileContent(getPath(), ref);
                    info = TypeInfo.NON_DIRECTORY_CONFIRMED;
                    resolved = true;
                } catch (IOException e) {
                    if (e.getCause() instanceof IOException
                            && e.getCause().getCause() instanceof JsonMappingException) {
                        metadata = repo.getDirectoryContent(getPath(), ref);
                        info = TypeInfo.DIRECTORY_CONFIRMED;
                        resolved = true;
                    } else {
                        throw e;
                    }
                }
                break;
            }
        } catch (FileNotFoundException e) {
            metadata = null;
            resolved = true;
        }
    }
    return metadata;
}