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.hadoop.hbase.wal.LogRecoveredEditsOutputSink.java

/**
 * Close all of the output streams./*from  w w w.j a v a  2 s.c  o m*/
 * @return the list of paths written.
 */
List<Path> close() throws IOException {
    Preconditions.checkState(!closeAndCleanCompleted);

    final List<Path> paths = new ArrayList<>();
    final List<IOException> thrown = Lists.newArrayList();
    ThreadPoolExecutor closeThreadPool = Threads.getBoundedCachedThreadPool(numThreads, 30L, TimeUnit.SECONDS,
            new ThreadFactory() {
                private int count = 1;

                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r, "split-log-closeStream-" + count++);
                    return t;
                }
            });
    CompletionService<Void> completionService = new ExecutorCompletionService<>(closeThreadPool);
    boolean progress_failed;
    try {
        progress_failed = executeCloseTask(completionService, thrown, paths);
    } catch (InterruptedException e) {
        IOException iie = new InterruptedIOException();
        iie.initCause(e);
        throw iie;
    } catch (ExecutionException e) {
        throw new IOException(e.getCause());
    } finally {
        closeThreadPool.shutdownNow();
    }
    if (!thrown.isEmpty()) {
        throw MultipleIOException.createIOException(thrown);
    }
    writersClosed = true;
    closeAndCleanCompleted = true;
    if (progress_failed) {
        return null;
    }
    return paths;
}

From source file:org.fluentd.jvmwatcher.LocalJvmInfo.java

/**
 * Load JVM management agent./*w w  w  .ja v a 2s  . com*/
 * @throws IOException
 */
private void loadManagementAgent() throws IOException {
    VirtualMachine vm = null;
    String name = String.valueOf(this.jvmId_);
    try {
        vm = VirtualMachine.attach(name);
    } catch (AttachNotSupportedException x) {
        IOException ioe = new IOException(x.getMessage());
        ioe.initCause(x);
        throw ioe;
    }

    // create management-agent.jar path
    String home = vm.getSystemProperties().getProperty("java.home");

    // ${java.home}/jre/lib/management-agent.jar or ${java.home}/lib in build environments.
    String agent = home + File.separator + "jre" + File.separator + "lib" + File.separator
            + "management-agent.jar";
    File file = new File(agent);
    if (!file.exists()) {
        agent = home + File.separator + "lib" + File.separator + "management-agent.jar";
        file = new File(agent);
        if (!file.exists()) {
            throw new IOException("Management agent not found");
        }
    }

    agent = file.getCanonicalPath();
    try {
        vm.loadAgent(agent, "com.sun.management.jmxremote");
    } catch (AgentLoadException ex) {
        IOException ioe = new IOException(ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    } catch (AgentInitializationException ex) {
        IOException ioe = new IOException(ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }

    // get the connector address
    Properties agentProps = vm.getAgentProperties();
    this.mbeanAddress_ = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);

    vm.detach();
}

From source file:org.cloudata.core.tabletserver.UploaderCache.java

public Map<String, TabletMapFile> close() throws IOException {
    //  ?? ./*w w  w.java 2  s  .c  om*/
    LOG.info("Start close:" + tabletInfo);
    try {
        Map<String, TabletMapFile> savedMapFiles = saveMemoryToDisk();

        if (savedMapFiles != null) {
            merger.addTabletMapFiles(savedMapFiles);
            init();
        }
        LOG.info("merger.addTabletMapFiles()");

        merger.requestStop();

        while (!merger.ended) {
            try {
                Thread.sleep(5 * 1000);
            } catch (InterruptedException e) {
                return null;
            }
            if (merger.exception != null) {
                throw merger.exception;
            }
        }

        LOG.info("merger.ended");
        //? merge  .
        Map<String, TabletMapFile> result = merger.mergeAndSend();

        // ? 
        GPath path = Tablet.getTabletLocalTempPath(conf, tabletInfo, uploadActionId);
        CloudataFileSystem localFs = CloudataFileSystem.get(conf, "local");
        localFs.delete(path, true);

        LOG.info("End close:" + tabletInfo);
        return result;
    } catch (Exception e) {
        merger.requestStop();
        if (e instanceof IOException) {
            throw (IOException) e;
        } else {
            IOException err = new IOException(e.getMessage());
            err.initCause(e);
            throw err;
        }
    }
}

From source file:org.apache.hadoop.hbase.wal.LogRecoveredEditsOutputSink.java

private List<IOException> closeLogWriters(List<IOException> thrown) throws IOException {
    if (writersClosed) {
        return thrown;
    }//w  w  w  .  ja v  a  2 s . c  om
    if (thrown == null) {
        thrown = Lists.newArrayList();
    }
    try {
        for (WriterThread writerThread : writerThreads) {
            while (writerThread.isAlive()) {
                writerThread.setShouldStop(true);
                writerThread.interrupt();
                try {
                    writerThread.join(10);
                } catch (InterruptedException e) {
                    IOException iie = new InterruptedIOException();
                    iie.initCause(e);
                    throw iie;
                }
            }
        }
    } finally {
        WALSplitter.WriterAndPath wap = null;
        for (WALSplitter.SinkWriter tmpWAP : writers.values()) {
            try {
                wap = (WALSplitter.WriterAndPath) tmpWAP;
                wap.writer.close();
            } catch (IOException ioe) {
                LOG.error("Couldn't close log at {}", wap.path, ioe);
                thrown.add(ioe);
                continue;
            }
            LOG.info("Closed log " + wap.path + " (wrote " + wap.editsWritten + " edits in "
                    + (wap.nanosSpent / 1000 / 1000) + "ms)");
        }
        writersClosed = true;
    }

    return thrown;
}

From source file:com.adito.vfs.webdav.methods.GET.java

/**
 * <p>//from w ww  . j  a va 2  s. c om
 * Process the <code>GET</code> method.
 * </p>
 */
public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException {

    String handle = VFSLockManager.getNewHandle();
    VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, true, handle);

    try {
        doHead(transaction, resource);

        try {
            if (resource.isCollection() || resource.isMount()) {

                if (SystemProperties.get("adito.disableFolderBrowsing", "true").equals("true")
                        && !resource.isBrowsable()) {
                    transaction.getResponse().sendError(404);
                    return;
                }

                String mime = COLLECTION_MIME_TYPE + "; charset=\"utf-8\"";
                transaction.setContentType(mime);

                Util.noCache(transaction.getResponse());

                PrintWriter out = transaction.write("utf-8");
                String path = resource.getFullPath();
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Collection: " + path + "</title>");
                out.println("</head>");
                out.println("<body>");
                out.println("<h2>Collection: " + path + "</h2>");
                out.println("<table>");
                out.println("<thead>");
                out.println("<tr>");
                out.println("<td>Name</td>");
                out.println("<td>Type</td>");
                out.println("<td>Size</td>");
                out.println("<td>Date</td>");
                out.println("</tr>");
                out.println("</thead>");
                out.println("<tbody>");

                /* Process the parent */
                VFSResource parent = resource.getParent();
                if (parent != null && (parent.isBrowsable()
                        || !SystemProperties.get("adito.disableFolderBrowsing", "true").equals("true"))) {
                    out.println("<tr>");
                    out.print("<td><li><a href=\"..\">../</a></td>");
                    out.println("<td>Dir</td><td>");
                    try {
                        out.println(parent.getFile().getContent().getSize());
                    } catch (Exception e) {
                    }
                    out.println("</td><td>");
                    try {
                        out.println(SimpleDateFormat.getDateTimeInstance()
                                .format(new Date(parent.getFile().getContent().getLastModifiedTime())));
                    } catch (Exception e) {
                    }
                    out.println("</td></tr>");
                }

                /* Process the children */
                Iterator iterator = resource.getChildren();
                if (iterator != null) {
                    while (iterator.hasNext()) {
                        VFSResource child = (VFSResource) iterator.next();
                        String childPath = child.getDisplayName();

                        out.println("<tr>");
                        out.print("<td><li><a href=\"" + child.getWebFolderPath() + "\">" + childPath
                                + "</a></td>");
                        if (child.isCollection())
                            out.println("<td>Dir</td><td>");
                        else if (child.isResource())
                            out.println("<td>Resource</td><td>");
                        else
                            out.println("<td>Unknown</td><td>");
                        try {
                            out.println(child.getFile().getContent().getSize());
                        } catch (Exception e) {
                        }
                        out.println("</td><td>");
                        try {
                            out.println(SimpleDateFormat.getDateTimeInstance()
                                    .format(new Date(child.getFile().getContent().getLastModifiedTime())));
                        } catch (Exception e) {
                        }
                        out.println("</td></tr>");
                        out.println("</tr>");
                    }
                }
                out.println("</tbody>");
                out.println("</table>");
                out.println("</html>");
                out.flush();
                if (resource.getMount() != null) {
                    resource.getMount().resourceAccessList(resource, transaction, null);
                }
                return;
            }
        } catch (Exception e) {
            if (resource.getMount() != null) {
                resource.getMount().resourceAccessList(resource, transaction, e);
            }
            IOException ioe = new IOException(e.getMessage());
            ioe.initCause(e);
            throw ioe;
        }

        int total = 0;
        try {

            Range[] ranges = null;

            try {
                ranges = processRangeHeader(transaction, resource);
            } catch (IOException ex) {
                // Invalid range means send full entity with 200 OK.
                ranges = null;
            }

            transaction.setHeader("Content-Type", resource.getContentType());

            resource.getMount().resourceAccessDownloading(resource, transaction);

            OutputStream out = transaction.getOutputStream();
            byte buffer[] = new byte[32768];

            InputStream in = null;

            try {

                if (ranges == null || ranges.length > 1 /* We dont support multiple ranges yet */) {
                    /* Processing a normal resource request */
                    in = resource.getInputStream();
                    int k;
                    while ((k = in.read(buffer)) != -1) {
                        out.write(buffer, 0, k);
                        total += k;
                    }
                } else {
                    /* Process a single range */

                    RandomAccessContent content = resource.getFile().getContent()
                            .getRandomAccessContent(RandomAccessMode.READ);

                    content.seek(ranges[0].startPosition);
                    in = content.getInputStream();

                    long count = ranges[0].count;
                    int k;
                    while (count > 0) {
                        while ((k = in.read(buffer, 0,
                                (int) (count < buffer.length ? count : buffer.length))) > 0) {
                            out.write(buffer, 0, k);
                            total += k;
                            count -= k;
                        }
                    }

                    transaction.setHeader("Content-Range",
                            "bytes " + ranges[0].startPosition + "-" + ranges[0].startPosition + ranges[0].count
                                    + "/" + resource.getFile().getContent().getSize());

                    transaction.setStatus(206 /* Partial */);

                }
            } finally {
                Util.closeStream(in);
            }
            resource.getMount().resourceAccessDownloadComplete(resource, transaction, null);
        } catch (IOException ioe) {
            resource.getMount().resourceAccessDownloadComplete(resource, transaction, ioe);
            throw ioe;
        }
    } finally {
        VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle);
    }

}

From source file:com.sslexplorer.vfs.webdav.methods.GET.java

/**
 * <p>/*from  www .  ja  v  a 2 s .  com*/
 * Process the <code>GET</code> method.
 * </p>
 */
public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException {

    String handle = VFSLockManager.getNewHandle();
    VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, true, handle);

    try {
        doHead(transaction, resource);

        try {
            if (resource.isCollection() || resource.isMount()) {

                if (SystemProperties.get("sslexplorer.disableFolderBrowsing", "true").equals("true")
                        && !resource.isBrowsable()) {
                    transaction.getResponse().sendError(404);
                    return;
                }

                String mime = COLLECTION_MIME_TYPE + "; charset=\"utf-8\"";
                transaction.setContentType(mime);

                Util.noCache(transaction.getResponse());

                PrintWriter out = transaction.write("utf-8");
                String path = resource.getFullPath();
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Collection: " + path + "</title>");
                out.println("</head>");
                out.println("<body>");
                out.println("<h2>Collection: " + path + "</h2>");
                out.println("<table>");
                out.println("<thead>");
                out.println("<tr>");
                out.println("<td>Name</td>");
                out.println("<td>Type</td>");
                out.println("<td>Size</td>");
                out.println("<td>Date</td>");
                out.println("</tr>");
                out.println("</thead>");
                out.println("<tbody>");

                /* Process the parent */
                VFSResource parent = resource.getParent();
                if (parent != null && (parent.isBrowsable()
                        || !SystemProperties.get("sslexplorer.disableFolderBrowsing", "true").equals("true"))) {
                    out.println("<tr>");
                    out.print("<td><li><a href=\"..\">../</a></td>");
                    out.println("<td>Dir</td><td>");
                    try {
                        out.println(parent.getFile().getContent().getSize());
                    } catch (Exception e) {
                    }
                    out.println("</td><td>");
                    try {
                        out.println(SimpleDateFormat.getDateTimeInstance()
                                .format(new Date(parent.getFile().getContent().getLastModifiedTime())));
                    } catch (Exception e) {
                    }
                    out.println("</td></tr>");
                }

                /* Process the children */
                Iterator iterator = resource.getChildren();
                if (iterator != null) {
                    while (iterator.hasNext()) {
                        VFSResource child = (VFSResource) iterator.next();
                        String childPath = child.getDisplayName();

                        out.println("<tr>");
                        out.print("<td><li><a href=\"" + child.getWebFolderPath() + "\">" + childPath
                                + "</a></td>");
                        if (child.isCollection())
                            out.println("<td>Dir</td><td>");
                        else if (child.isResource())
                            out.println("<td>Resource</td><td>");
                        else
                            out.println("<td>Unknown</td><td>");
                        try {
                            out.println(child.getFile().getContent().getSize());
                        } catch (Exception e) {
                        }
                        out.println("</td><td>");
                        try {
                            out.println(SimpleDateFormat.getDateTimeInstance()
                                    .format(new Date(child.getFile().getContent().getLastModifiedTime())));
                        } catch (Exception e) {
                        }
                        out.println("</td></tr>");
                        out.println("</tr>");
                    }
                }
                out.println("</tbody>");
                out.println("</table>");
                out.println("</html>");
                out.flush();
                if (resource.getMount() != null) {
                    resource.getMount().resourceAccessList(resource, transaction, null);
                }
                return;
            }
        } catch (Exception e) {
            if (resource.getMount() != null) {
                resource.getMount().resourceAccessList(resource, transaction, e);
            }
            IOException ioe = new IOException(e.getMessage());
            ioe.initCause(e);
            throw ioe;
        }

        int total = 0;
        try {

            Range[] ranges = null;

            try {
                ranges = processRangeHeader(transaction, resource);
            } catch (IOException ex) {
                // Invalid range means send full entity with 200 OK.
                ranges = null;
            }

            transaction.setHeader("Content-Type", resource.getContentType());

            resource.getMount().resourceAccessDownloading(resource, transaction);

            OutputStream out = transaction.getOutputStream();
            byte buffer[] = new byte[32768];

            InputStream in = null;

            try {

                if (ranges == null || ranges.length > 1 /* We dont support multiple ranges yet */) {
                    /* Processing a normal resource request */
                    in = resource.getInputStream();
                    int k;
                    while ((k = in.read(buffer)) != -1) {
                        out.write(buffer, 0, k);
                        total += k;
                    }
                } else {
                    /* Process a single range */

                    RandomAccessContent content = resource.getFile().getContent()
                            .getRandomAccessContent(RandomAccessMode.READ);

                    content.seek(ranges[0].startPosition);
                    in = content.getInputStream();

                    long count = ranges[0].count;
                    int k;
                    while (count > 0) {
                        while ((k = in.read(buffer, 0,
                                (int) (count < buffer.length ? count : buffer.length))) > 0) {
                            out.write(buffer, 0, k);
                            total += k;
                            count -= k;
                        }
                    }

                    transaction.setHeader("Content-Range",
                            "bytes " + ranges[0].startPosition + "-" + ranges[0].startPosition + ranges[0].count
                                    + "/" + resource.getFile().getContent().getSize());

                    transaction.setStatus(206 /* Partial */);

                }
            } finally {
                Util.closeStream(in);
            }
            resource.getMount().resourceAccessDownloadComplete(resource, transaction, null);
        } catch (IOException ioe) {
            resource.getMount().resourceAccessDownloadComplete(resource, transaction, ioe);
            throw ioe;
        }
    } finally {
        VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle);
    }

}

From source file:org.pixmob.freemobile.netstat.SyncService.java

private void registerDevice(String deviceId) throws IOException {
    final JSONObject json = new JSONObject();
    try {//from ww  w  .j  av a2 s  . c  o  m
        json.put("brand", Build.BRAND);
        json.put("model", Build.MODEL);
    } catch (JSONException e) {
        final IOException ioe = new IOException("Failed to prepare device registration request");
        ioe.initCause(e);
        throw ioe;
    }

    final byte[] rawJson = json.toString().getBytes("UTF-8");
    Log.i(TAG, "Registering device");

    final String url = createServerUrl("/device/" + deviceId);
    final HttpClient client = createHttpClient();
    try {
        client.put(url).expect(HttpURLConnection.HTTP_CREATED).content(rawJson, "application/json").execute();
    } catch (HttpClientException e) {
        final IOException ioe = new IOException("Failed to register device " + deviceId);
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:com.silverwrist.dynamo.unistore.BinaryPartImpl.java

public InputStream getDataStream() throws IOException {
    if (m_ops == null) { // we've been deleted!
        IOException ioe = new IOException("Part has been deleted");
        ioe.initCause(new DatabaseException(BinaryPartImpl.class, "UniStoreMessages", "part.deleted"));
        throw ioe;

    } // end if/*from  www.j a  v  a 2 s .  co m*/

    try { // call through to the database to get the data stream
        return m_ops.getData(m_parent.getMessageID(), m_part);

    } // end try
    catch (DatabaseException e) { // create an IOException and chain this one onto it
        IOException ioe = new IOException("Database error retrieving data stream");
        ioe.initCause(e);
        throw ioe;

    } // end catch

}

From source file:com.wfreitas.camelsoap.SoapClient.java

private synchronized DocumentBuilder getDocBuilder() throws IOException {
    try {//from w w  w.j  a va  2s  . c o m
        return docBuilderFactory.newDocumentBuilder();
    } catch (final ParserConfigurationException pce) {
        final IOException ioe = new IOException("Could not create document builder");
        ioe.initCause(pce);
        throw ioe;
    }
}