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:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java

public void stop() throws IOException {
    MBeanServer server = getMBeanServer();
    IOException error = null;/*w w  w.j av  a  2 s .c o m*/
    if (exposeMBeansAsUPNP.booleanValue()) {
        try {
            ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
            NotificationEmitter emmiter = (NotificationEmitter) MBeanServerInvocationHandler
                    .newProxyInstance(server, delegate, NotificationEmitter.class, false);
            emmiter.removeNotificationListener(this, null, this);
        } catch (Exception ex) {
            // MX4J throws an unexpected ListenerNotFoundException with jre 1.5.06.. works nice with sun JMX impl
            if (!(ex instanceof ListenerNotFoundException)) {
                IOException ioEx = new IOException("UPNPConnector stop error");
                ioEx.initCause(ex);
                error = ioEx;
            }
        }
        synchronized (STOP_PROCESS) {
            // now stop all the remaining Devices
            for (Iterator i = registeredMBeans.values().iterator(); i.hasNext();) {
                UPNPMBeanDevice dv = (UPNPMBeanDevice) i.next();
                try {
                    dv.stop();
                } catch (IOException ex) {
                    log.error("Error during UPNPMBean device stop", ex);
                }
            }
            registeredMBeans.clear();
        }
    }
    if (exposeUPNPAsMBeans.booleanValue()) {
        try {
            server.unregisterMBean(discoveryBeanName);
        } catch (Exception ex) {
            IOException ioEx = new IOException("Error occured during MBeans discovery");
            ioEx.initCause(ex);
            throw ioEx;
        }
    }
    if (error != null) {
        throw error;
    }
}

From source file:org.onecmdb.core.utils.transform.excel.ExcelDataSource.java

public synchronized List<String[]> load() throws IOException {
    if (loaded) {
        return (lines);
    }//from  ww  w .  j av  a2  s .c  o m
    int lineIndex = 0;
    for (URL url : urls) {
        // Remove Options.
        String spec = url.toExternalForm();
        int index = spec.indexOf("?");
        if (index > 0) {
            spec = spec.substring(0, index);
        }
        URL nUrl = new URL(spec);
        if (rootPath != null) {
            nUrl = new URL(nUrl.getProtocol(), nUrl.getHost(), nUrl.getPort(), rootPath + "/" + nUrl.getFile());
        }
        InputStream in = nUrl.openStream();
        Workbook workbook = null;
        try {
            workbook = Workbook.getWorkbook(in);
            String query = url.getQuery();
            Sheet sheet = getSheet(workbook, query, nUrl.toExternalForm());

            log.info("Excel[" + url + "] using sheet " + sheet.getName());
            columns = sheet.getColumns();
            for (int row = 0; row < sheet.getRows(); row++) {
                String rowData[] = new String[sheet.getColumns()];
                for (int col = 0; col < sheet.getColumns(); col++) {
                    Cell cell = sheet.getCell(col, row);
                    String text = cell.getContents();
                    rowData[col] = text;
                }
                if (row < headerLines) {
                    headers.add(rowData);
                } else {
                    lines.add(rowData);
                }
            }
        } catch (BiffException e1) {
            e1.printStackTrace();
            throw new IOException("Problem open Execl file '" + url + "' : " + e1.getMessage());
        } 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;
    // Update header name mapping...
    String headers[] = getHeaderData();
    for (int i = 0; i < headers.length; i++) {
        headerMap.put(headers[i], i);
    }
    return (lines);
}

From source file:marytts.tools.voiceimport.AllophonesExtractor.java

public MaryHttpClient getMaryClient() throws IOException {
    if (mary == null) {
        try {/*from  w  w  w.j  av  a  2  s . co m*/
            Address server = new Address(db.getProp(db.MARYSERVERHOST),
                    Integer.parseInt(db.getProp(db.MARYSERVERPORT)));
            mary = new MaryHttpClient(server);
        } catch (IOException e) {
            IOException myIOE = new IOException("Could not connect to Maryserver at "
                    + db.getProp(db.MARYSERVERHOST) + " " + db.getProp(db.MARYSERVERPORT));
            myIOE.initCause(e);
            throw myIOE;
        }
    }
    return mary;
}

From source file:org.hyperic.hq.agent.client.AgentConnection.java

protected Socket getSocket() throws IOException {
    Socket s;/*www.j  a v a 2 s .  co m*/
    // Connect to the remote agent
    try {
        s = new Socket(_agentAddress, _agentPort);
    } catch (IOException exc) {
        String msg = "Error connecting to agent @ (" + _agentAddress + ":" + _agentPort + "): "
                + exc.getMessage();
        IOException toThrow = new IOException(msg);
        // call initCause instead of constructor to be java 1.5 compat
        toThrow.initCause(exc);
        throw toThrow;
    }
    s.setSoTimeout(SOCKET_TIMEOUT);
    return s;
}

From source file:org.kuali.rice.core.impl.config.property.ConfigParserImpl.java

/**
 * @param name name of the node//from  w w  w . jav a 2 s. c o m
 * @param location config file location
 * @param n the node
 * @param sb a StringBuilder into which to set contents of the node, preserving any XML content
 * @throws IOException
 */
protected void getNodeValue(String name, String location, Node n, StringBuilder sb) throws IOException {
    NodeList children = n.getChildNodes();
    // accumulate all content (preserving any XML content)
    try {
        sb.setLength(0);
        for (int j = 0; j < children.getLength(); j++) {
            sb.append(XmlJotter.jotNode(children.item(j), true));
        }
    } catch (XmlException te) {
        IOException ioe = new IOException(
                "Error obtaining parameter '" + name + "' from config resource: " + location);
        ioe.initCause(te);
        throw ioe;
    }
}

From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.SoundcloudTracksStore.java

@Override
void parseArrayResponse(InputStream in, ResponseParserArray responseParser) throws IOException {
    try {//from w w  w  .  j a v a 2s . c om
        String result = convertStreamToString(in);
        responseParser.parseResponse(new JSONArray(result));
    } catch (JSONException e) {
        final IOException ioe = new IOException("Could not parse the response");
        ioe.initCause(e);
        throw ioe;
    } catch (IOException e) {
        final IOException ioe = new IOException("Could not parse the response");
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.SoundcloudTracksStore.java

@Override
void parseSingleResponse(InputStream in, ResponseParserSingle responseParser) throws IOException {
    try {/*from  ww w  . ja v a  2  s.  c o m*/
        String result = convertStreamToString(in);
        responseParser.parseResponse(new JSONObject(result));
    } catch (JSONException e) {
        final IOException ioe = new IOException("Could not parse the response");
        ioe.initCause(e);
        throw ioe;
    } catch (IOException e) {
        final IOException ioe = new IOException("Could not parse the response");
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:ch.cyberduck.core.cf.CFSession.java

@Override
protected void login(final LoginController controller, final Credentials credentials) throws IOException {
    final FilesClient client = this.getClient();
    client.setUserName(credentials.getUsername());
    client.setPassword(credentials.getPassword());
    try {//  w w  w .  j  a  va 2  s.c  om
        if (!client.login()) {
            this.message(Locale.localizedString("Login failed", "Credentials"));
            controller.fail(host.getProtocol(), credentials);
            this.login();
        }
    } catch (HttpException e) {
        IOException failure = new IOException(e.getMessage());
        failure.initCause(e);
        throw failure;
    }
}

From source file:org.apache.tez.mapreduce.input.SimpleInput.java

public org.apache.hadoop.mapred.InputSplit getOldSplitDetails(TaskSplitIndex splitMetaInfo) throws IOException {
    Path file = new Path(splitMetaInfo.getSplitLocation());
    FileSystem fs = FileSystem.getLocal(jobConf);
    file = fs.makeQualified(file);//  www.java 2 s.  co  m
    LOG.info("Reading input split file from : " + file);
    long offset = splitMetaInfo.getStartOffset();

    FSDataInputStream inFile = fs.open(file);
    inFile.seek(offset);
    String className = Text.readString(inFile);
    Class<org.apache.hadoop.mapred.InputSplit> cls;
    try {
        cls = (Class<org.apache.hadoop.mapred.InputSplit>) jobConf.getClassByName(className);
    } catch (ClassNotFoundException ce) {
        IOException wrap = new IOException("Split class " + className + " not found");
        wrap.initCause(ce);
        throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(jobConf);
    Deserializer<org.apache.hadoop.mapred.InputSplit> deserializer = (Deserializer<org.apache.hadoop.mapred.InputSplit>) factory
            .getDeserializer(cls);
    deserializer.open(inFile);
    org.apache.hadoop.mapred.InputSplit split = deserializer.deserialize(null);
    long pos = inFile.getPos();
    reporter.getCounter(TaskCounter.SPLIT_RAW_BYTES).increment(pos - offset);
    inFile.close();
    return split;
}

From source file:org.apache.tez.mapreduce.input.SimpleInput.java

public org.apache.hadoop.mapreduce.InputSplit getNewSplitDetails(TaskSplitIndex splitMetaInfo)
        throws IOException {
    Path file = new Path(splitMetaInfo.getSplitLocation());
    long offset = splitMetaInfo.getStartOffset();

    // Split information read from local filesystem.
    FileSystem fs = FileSystem.getLocal(jobConf);
    file = fs.makeQualified(file);//from  ww w .  j av  a 2  s. c om
    LOG.info("Reading input split file from : " + file);
    FSDataInputStream inFile = fs.open(file);
    inFile.seek(offset);
    String className = Text.readString(inFile);
    Class<org.apache.hadoop.mapreduce.InputSplit> cls;
    try {
        cls = (Class<org.apache.hadoop.mapreduce.InputSplit>) jobConf.getClassByName(className);
    } catch (ClassNotFoundException ce) {
        IOException wrap = new IOException("Split class " + className + " not found");
        wrap.initCause(ce);
        throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(jobConf);
    Deserializer<org.apache.hadoop.mapreduce.InputSplit> deserializer = (Deserializer<org.apache.hadoop.mapreduce.InputSplit>) factory
            .getDeserializer(cls);
    deserializer.open(inFile);
    org.apache.hadoop.mapreduce.InputSplit split = deserializer.deserialize(null);
    long pos = inFile.getPos();
    reporter.getCounter(TaskCounter.SPLIT_RAW_BYTES).increment(pos - offset);
    inFile.close();
    return split;
}