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.apache.jackrabbit.webdav.client.methods.DavMethodBase.java

/**
 *
 * @param requestBody/*  ww w. ja  v a2  s. c  o m*/
 * @throws IOException
 */
public void setRequestBody(XmlSerializable requestBody) throws IOException {
    try {
        Document doc = DomUtil.createDocument();
        doc.appendChild(requestBody.toXml(doc));
        setRequestBody(doc);
    } catch (ParserConfigurationException e) {
        IOException exception = new IOException("XML parser configuration error");
        exception.initCause(e);
        throw exception;
    }
}

From source file:org.onecmdb.core.utils.transform.csv.CSVDataSource.java

public synchronized List<String> load() throws IOException {
    if (loaded) {
        return (lines);
    }/*w ww .  jav  a  2 s .  c o  m*/

    lines = new ArrayList<String>();
    int lineIndex = 0;
    for (URL url : urls) {
        URL nUrl = url;
        if (rootPath != null) {
            nUrl = new URL(nUrl.getProtocol(), nUrl.getHost(), nUrl.getPort(), rootPath + "/" + nUrl.getFile());
        }
        InputStream in = nUrl.openStream();
        try {
            LineNumberReader lin = new LineNumberReader(new InputStreamReader(in));
            boolean eof = false;
            while (!eof) {

                String line = lin.readLine();
                if (line == null) {
                    eof = true;
                    continue;
                }
                // Check if line is not terminated due to nl in fields.
                line = handleEndOfLine(lin, line);
                lineIndex++;
                if (lineIndex < headerLines) {
                    log.debug("Add Header:" + line);
                    headers.add(line);
                    continue;
                }
                log.debug("Add Line:[" + lineIndex + "]" + line);
                lines.add(line);
            }
        } catch (IOException de) {
            IOException e = new IOException("Parse error in <" + url.toExternalForm() + ">, ");
            e.initCause(de);
            throw e;
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
    loaded = true;

    String header = getHeaderData();
    if (headers != null) {
        String headers[] = header.split(getColDelimiter());
        for (int i = 0; i < headers.length; i++) {
            headerMap.put(headers[i], i);
        }
    }
    return (lines);
}

From source file:org.paxle.core.doc.impl.BasicDocumentFactory.java

public <Doc> Map<String, DataHandler> marshal(Doc document, OutputStream output) throws IOException {
    try {/*from  ww w  .j av a 2 s.  co  m*/

        final JaxbAttachmentMarshaller am = new JaxbAttachmentMarshaller();
        final Marshaller m = context.createMarshaller();

        m.setAdapter(JaxbDocAdapter.class, new JaxbDocAdapter());
        m.setAdapter(JaxbFileAdapter.class, new JaxbFileAdapter(this.tempFileManager));
        m.setAdapter(JaxbFieldMapAdapter.class, new JaxbFieldMapAdapter(this.tempFileManager));
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //         m.setProperty("com.sun.xml.bind.ObjectFactory", new BasicJaxbFactory());
        m.setAttachmentMarshaller(am);

        m.marshal(document, output);
        output.flush();

        return am.getAttachmentsMap();
    } catch (JAXBException e) {
        final IOException ioe = new IOException(
                String.format("Unable to marshal the document '%s'.", document.getClass().getName()));
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:org.mozilla.mozstumbler.service.core.http.HttpUtil.java

private URLConnection openConnectionWithProxy(URL url) throws IOException {
    Proxy proxy = Proxy.NO_PROXY;

    ProxySelector proxySelector = ProxySelector.getDefault();
    if (proxySelector != null) {
        URI uri;//from   w w  w.j  a va  2  s  .  co m
        try {
            uri = url.toURI();
        } catch (URISyntaxException e) {
            IOException ioe = new IOException(url.toString());
            ioe.initCause(e);
            throw ioe;
        }

        List<Proxy> proxies = proxySelector.select(uri);
        if (proxies != null && !proxies.isEmpty()) {
            proxy = proxies.get(0);
        }
    }

    return url.openConnection(proxy);
}

From source file:com.uphyca.kitkat.storage.internal.impl.LiveSdkSkyDriveClient.java

@Override
public void delete(String path) throws IOException {
    initializeIfNecessary();/* www  . j  a v  a  2s. c om*/
    if (mLiveConnectClient == null) {
        return;
    }
    try {
        mLiveConnectClient.delete(path);
    } catch (LiveOperationException e) {
        IOException ioException = new IOException("Failed to delete " + path);
        ioException.initCause(e);
        throw ioException;
    }
}

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

/**
 * @see DavMethod#getResponseBodyAsDocument()
 *///from w w  w . j a va2s.  c om
public Document getResponseBodyAsDocument() throws IOException {
    if (responseDocument != null) {
        // response has already been read
        return responseDocument;
    }

    InputStream in = getResponseBodyAsStream();
    if (in != null) {
        // read response and try to build a xml document
        try {
            return DomUtil.parseDocument(in);
        } catch (ParserConfigurationException e) {
            IOException exception = new IOException("XML parser configuration error");
            exception.initCause(e);
            throw exception;
        } catch (SAXException e) {
            IOException exception = new IOException("XML parsing error");
            exception.initCause(e);
            throw exception;
        } finally {
            in.close();
        }
    }
    // no body or no parseable.
    return null;
}

From source file:nl.nn.adapterframework.ftp.FTPsClient.java

protected void _connectAction_() throws IOException {
    // if explicit FTPS, the socket connection is establisch unsecure
    if (session.getFtpType() == FtpSession.FTPS_EXPLICIT_SSL
            || session.getFtpType() == FtpSession.FTPS_EXPLICIT_TLS) {
        orgSocket = _socket_; // remember the normal socket 

        // set the properties to aan appropriate default
        _socket_.setSoTimeout(10000);//from  w w w. j a  v  a  2 s  . com
        _socket_.setKeepAlive(true);

        // now send the command to inform the server to transform the connection 
        // into a secure connection
        log.debug(_readReply(orgSocket.getInputStream(), true));
        String protocol = getProtocol();
        log.debug(_sendCommand("AUTH " + protocol, orgSocket.getOutputStream(), orgSocket.getInputStream()));

        // replace the normal socket with the secure one 
        try {
            socketFactory.initSSLContext();
            _socket_ = socketFactory.createSocket(orgSocket, orgSocket.getInetAddress().getHostAddress(),
                    orgSocket.getPort(), true);

            // send a dummy command over the secure connection without reading 
            // the reply
            // this allows us to call super._connectAction_()
            _sendCommand("FEAT", _socket_.getOutputStream(), null);
            super._connectAction_();
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
            IOException ioe = new IOException("Unexpected error");
            ioe.initCause(e);
            throw ioe;
        }
    } else {
        super._connectAction_();
    }
}

From source file:org.apache.pdfbox.filter.FlateFilter.java

/**
 * {@inheritDoc}/*from   w  w w . j a  va2  s.  com*/
 */
public void decode(InputStream compressedData, OutputStream result, COSDictionary options, int filterIndex)
        throws IOException {
    COSBase baseObj = options.getDictionaryObject(COSName.DECODE_PARMS, COSName.DP);
    COSDictionary dict = null;
    if (baseObj instanceof COSDictionary) {
        dict = (COSDictionary) baseObj;
    } else if (baseObj instanceof COSArray) {
        COSArray paramArray = (COSArray) baseObj;
        if (filterIndex < paramArray.size()) {
            dict = (COSDictionary) paramArray.getObject(filterIndex);
        }
    } else if (baseObj != null) {
        throw new IOException(
                "Error: Expected COSArray or COSDictionary and not " + baseObj.getClass().getName());
    }

    int predictor = -1;
    int colors = -1;
    int bitsPerPixel = -1;
    int columns = -1;
    ByteArrayInputStream bais = null;
    ByteArrayOutputStream baos = null;
    if (dict != null) {
        predictor = dict.getInt(COSName.PREDICTOR);
        if (predictor > 1) {
            colors = dict.getInt(COSName.COLORS);
            bitsPerPixel = dict.getInt(COSName.BITS_PER_COMPONENT);
            columns = dict.getInt(COSName.COLUMNS);
        }
    }

    try {
        baos = decompress(compressedData);
        // Decode data using given predictor
        if (predictor == -1 || predictor == 1) {
            result.write(baos.toByteArray());
        } else {
            /*
             * Reverting back to default values
             */
            if (colors == -1) {
                colors = 1;
            }
            if (bitsPerPixel == -1) {
                bitsPerPixel = 8;
            }
            if (columns == -1) {
                columns = 1;
            }

            // Copy data to ByteArrayInputStream for reading
            bais = new ByteArrayInputStream(baos.toByteArray());

            byte[] decodedData = decodePredictor(predictor, colors, bitsPerPixel, columns, bais);
            bais.close();
            bais = null;

            result.write(decodedData);
        }
        result.flush();
    } catch (DataFormatException exception) {
        // if the stream is corrupt a DataFormatException may occur
        LOG.error("FlateFilter: stop reading corrupt stream due to a DataFormatException");
        // re-throw the exception, caller has to handle it
        IOException io = new IOException();
        io.initCause(exception);
        throw io;
    } finally {
        if (bais != null) {
            bais.close();
        }
        if (baos != null) {
            baos.close();
        }
    }
}

From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpMethodSupport.java

public byte[] getResponseBody() throws IOException {
    if (responseBody != null)
        return responseBody;

    long contentLength = httpMethod.getResponseContentLength();
    long now = System.nanoTime();

    InputStream instream = httpMethod.getResponseBodyAsStream();

    if (maxSize == 0 || (contentLength >= 0 && contentLength <= maxSize)) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        if (instream != null)
            Tools.writeAll(out, instream);

        responseReadTime = System.nanoTime() - now;
        responseBody = out.toByteArray();

        try {//www .  ja  v a  2  s  . c  o m
            if (StringUtils.hasContent(dumpFile)) {
                Tools.writeAll(new FileOutputStream(dumpFile), new ByteArrayInputStream(responseBody));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (decompress && responseBody.length > 0) {
            String compressionAlg = HttpClientSupport.getResponseCompressionType(httpMethod);
            if (compressionAlg != null) {
                try {
                    responseBody = CompressionSupport.decompress(compressionAlg, responseBody);
                } catch (Exception e) {
                    IOException ioe = new IOException("Decompression of response failed");
                    ioe.initCause(e);
                    throw ioe;
                }
            }
        }
    } else {
        try {
            if (StringUtils.hasContent(dumpFile) && instream != null) {
                FileOutputStream fileOutputStream = new FileOutputStream(dumpFile);
                Tools.writeAll(fileOutputStream, instream);
                responseReadTime = System.nanoTime() - now;
                fileOutputStream.close();
                instream = new FileInputStream(dumpFile);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        ByteArrayOutputStream outstream = instream == null ? new ByteArrayOutputStream()
                : Tools.readAll(instream, maxSize);

        if (responseReadTime == 0)
            responseReadTime = System.nanoTime() - now;

        responseBody = outstream.toByteArray();
    }

    // convert to ms
    responseReadTime /= 1000000;

    return responseBody;
}

From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java

public void start() throws IOException {
    MBeanServer server = getMBeanServer();
    if (exposeMBeansAsUPNP.booleanValue()) {
        try {//from  ww w . j  a  v a2 s  . c o  m
            ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
            NotificationEmitter emmiter = (NotificationEmitter) MBeanServerInvocationHandler
                    .newProxyInstance(server, delegate, NotificationEmitter.class, false);
            // register for MBeans registration
            emmiter.addNotificationListener(this, null, this);
        } catch (Exception ex) {
            IOException ioEx = new IOException("UPNPConnector start error");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (exposeUPNPAsMBeans.booleanValue()) {
        int timeout = 2500;
        if (env.containsKey(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)) {
            timeout = ((Integer) env.get(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)).intValue();
        }
        try {
            discoveryBeanName = new ObjectName("UPNPLib discovery:name=Discovery MBean_" + this.hashCode());
            UPNPDiscoveryMBean bean = new UPNPDiscovery(timeout, handleSSDPMessages.booleanValue(), true);
            server.registerMBean(bean, discoveryBeanName);
        } catch (Exception ex) {
            IOException ioEx = new IOException("Error occured during MBeans discovery");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (exposeExistingMBeansAsUPNP.booleanValue()) {
        int c = 0;
        Set objectInstances = super.getMBeanServer().queryNames(null, null);
        for (Iterator i = objectInstances.iterator(); i.hasNext();) {
            ObjectName name = (ObjectName) i.next();
            MBeanServerNotification not = new MBeanServerNotification(
                    MBeanServerNotification.REGISTRATION_NOTIFICATION, this, c++, name);
            handleNotification(not, this);
        }
    }
}