Example usage for java.io IOException initCause

List of usage examples for java.io IOException initCause

Introduction

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

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource.java

public InputStream createInputStream() throws IOException {
    try {//  w ww  . j a  v  a  2s  .  c o m
        return attachment.createInputStream(null);
    } catch (CoreException e) {
        IOException exception = new IOException("Failed to create source stream"); //$NON-NLS-1$
        exception.initCause(e);
        throw exception;
    }
}

From source file:com.elasticgrid.storage.amazon.s3.S3Storable.java

public InputStream asInputStream() throws IOException {
    try {//from w w w. j av a  2s .  co m
        return object.getDataInputStream();
    } catch (S3ServiceException e) {
        IOException ioe = new IOException("Can't get stream from storable");
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:com.axcessfinancial.fisintegration.platform.custom.ReceiverFileInputStream.java

@Override
public void close() throws IOException {
    super.close();

    if (!streamProcessingError) {
        if (moveToOnClose != null) {
            if (!FileUtils.moveFileWithCopyFallback(currentFile, moveToOnClose)) {
                logger.warn(String.format("Failed to move file from %s to %s\n", currentFile.getPath(),
                        moveToOnClose.getPath()));
            }//  w w  w  .  ja va2s .c  o  m
        } else if (deleteOnClose) {
            if (!currentFile.delete()) {
                try {
                    throw new DefaultMuleException(FileMessages.failedToDeleteFile(currentFile));
                } catch (DefaultMuleException e) {
                    IOException e2 = new IOException();
                    e2.initCause(e);
                    throw e2;
                }
            }
        }
    }
    if (closeListener != null) {
        closeListener.fileClose(currentFile);
    }
}

From source file:org.apache.jackrabbit.webdav.client.methods.XmlRequestEntity.java

public XmlRequestEntity(Document xmlDocument) throws IOException {
    super();/*from  w w w . j  a v a2  s. c  o m*/
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "no");
        transformer.transform(new DOMSource(xmlDocument), new StreamResult(out));
    } catch (TransformerException e) {
        log.error("XML serialization failed", e);
        IOException exception = new IOException("XML serialization failed");
        exception.initCause(e);
        throw exception;
    }

    delegatee = new StringRequestEntity(out.toString(), "text/xml", "UTF-8");
}

From source file:org.nuxeo.ecm.automation.client.jaxrs.impl.MultipartRequestEntity.java

public void writeTo(OutputStream arg0) throws IOException {
    try {// w w w  .  j a  v  a  2  s.  c om
        mp.writeTo(arg0);
    } catch (MessagingException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:com.cloudbees.plugins.registration.grandcentral.ApiUserProfileHandler.java

@Override
public ApiUserProfileResponse onCompleted(Response response) throws Exception {
    if (response.getStatusCode() == 200) {
        JSONObject json = JSONObject.fromObject(response.getResponseBody());
        try {//from   w ww  .j a  va2 s  . c o m
            String firstName = json.getString("first_name");
            String lastName = json.getString("last_name");
            String fullName = json.getString("full_name");
            String username = json.getString("username");
            List<CloudBeesAccount> accountNames = new ArrayList<CloudBeesAccount>();
            JSONArray accounts = json.getJSONArray("accounts");
            for (int i = 0; i < accounts.size(); i++) {
                JSONObject account = accounts.getJSONObject(i);
                String company = account.getString("company_name");
                String accountName = account.getString("account");
                accountNames.add(new CloudBeesAccountImpl(accountName, getDisplayNameOf(company, accountName)));
            }
            return new ApiUserProfileResponse(firstName, lastName, fullName, username, accountNames);
        } catch (JSONException e) {
            IOException ioe = new IOException("Unexpected response");
            ioe.initCause(e);
            throw ioe;
        }
    }
    throw new IOException("HTTP " + response.getStatusCode() + "/" + response.getStatusText());

}

From source file:com.rei.lolchat.smack.avatar.HttpClientAvatarRetriever.java

@Override
public byte[] getAvatar() throws IOException {
    HttpUriRequest request;// w  w w  . j a v  a 2 s .  c o  m
    try {
        request = new HttpGet(mUrl);
    } catch (IllegalArgumentException e) {
        IOException ioe = new IOException("Invalid url " + mUrl);
        ioe.initCause(e);
        throw ioe;
    }
    HttpResponse response = mClient.execute(request);
    HttpEntity entity = response.getEntity();
    InputStream in = entity.getContent();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        byte[] data = new byte[1024];
        int nbread;
        while ((nbread = in.read(data)) != -1) {
            os.write(data, 0, nbread);
        }
    } finally {
        in.close();
        os.close();
    }
    return os.toByteArray();
}

From source file:org.cloudata.core.client.scanner.AbstractTableScanner.java

@Override
public Row nextRow() throws IOException {
    try {// w  w w  .  ja v  a2s .c o  m
        if (isEnd()) {
            return null;
        }

        List<ScanCell> result = new ArrayList<ScanCell>();
        while (true) {
            ScanCell cell = next();
            if (cell == null) {
                if (lastCell != null) {
                    result.add(lastCell);
                    lastCell = cell;
                }
                setEnd(true);
                break;
            }

            if (lastCell != null && !cell.getRowKey().equals(lastCell.getRowKey())) {
                result.add(lastCell);
                lastCell = cell;
                break;
            }

            if (lastCell != null) {
                result.add(lastCell);
            }

            lastCell = cell;
        }

        if (result.size() == 0) {
            setEnd(true);
            return null;
        }

        Row row = new Row(result.get(0).getRowKey());

        ScanCell.addCells(row, columnName, result);

        return row;
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        IOException err = new IOException(e.getMessage());
        err.initCause(e);
        throw err;
    }
}

From source file:org.eclipse.mylyn.commons.net.http.CommonHttpClient3.java

protected boolean needsReauthentication(int code, IProgressMonitor monitor) throws IOException {
    final AuthenticationType authenticationType;
    if (code == HttpStatus.SC_UNAUTHORIZED || code == HttpStatus.SC_FORBIDDEN) {
        authenticationType = AuthenticationType.HTTP;
    } else if (code == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
        authenticationType = AuthenticationType.PROXY;
    } else {/*from  ww  w  .  ja  v  a  2  s .c  o m*/
        return false;
    }

    try {
        location.requestCredentials(authenticationType, null, monitor);
    } catch (UnsupportedRequestException e) {
        IOException ioe = new IOException(HttpStatus.getStatusText(code));
        ioe.initCause(e);
        throw ioe;
    } catch (UnsupportedOperationException e) {
        IOException ioe = new IOException(HttpStatus.getStatusText(code));
        ioe.initCause(e);
        throw ioe;
    }

    return true;
}

From source file:org.apache.hadoop.hdfs.server.datanode.BlockPoolManager.java

synchronized void startAll() throws IOException {
    try {//from   ww  w .  ja  v a2s.com
        UserGroupInformation.getLoginUser().doAs(new PrivilegedExceptionAction<Object>() {
            @Override
            public Object run() throws Exception {
                for (BPOfferService bpos : offerServices) {
                    bpos.start();
                }
                return null;
            }
        });
    } catch (InterruptedException ex) {
        IOException ioe = new IOException();
        ioe.initCause(ex.getCause());
        throw ioe;
    }
}