Example usage for java.io IOException getClass

List of usage examples for java.io IOException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.jwebsocket.plugins.flashbridge.FlashBridgePlugIn.java

@Override
public void engineStopped(WebSocketEngine aEngine) {
    if (mLog.isDebugEnabled()) {
        mLog.debug("Engine '" + aEngine.getId() + "' stopped.");
    }// w ww  . jav a2s .  c o m
    // every time an engine starts decrement counter
    mEngineInstanceCount--;
    // when last engine stopped also stop the FlashBridge
    if (mEngineInstanceCount <= 0) {
        super.engineStopped(aEngine);

        mIsRunning = false;
        long lStarted = new Date().getTime();

        try {
            // when done, close server socket
            // closing the server socket should lead to an exception
            // at accept in the bridgeProcess thread which terminates the
            // bridgeProcess
            if (mLog.isDebugEnabled()) {
                mLog.debug("Closing FlashBridge server socket...");
            }
            mServerSocket.close();
            if (mLog.isDebugEnabled()) {
                mLog.debug("Closed FlashBridge server socket.");
            }
        } catch (IOException ex) {
            mLog.error("(accept) " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
        }

        try {
            mBridgeThread.join(10000);
        } catch (InterruptedException ex) {
            mLog.error(ex.getClass().getSimpleName() + ": " + ex.getMessage());
        }
        if (mLog.isDebugEnabled()) {
            long lDuration = new Date().getTime() - lStarted;
            if (mBridgeThread.isAlive()) {
                mLog.warn("FlashBridge did not stopped after " + lDuration + "ms.");
            } else {
                mLog.debug("FlashBridge stopped after " + lDuration + "ms.");
            }
        }
    }
}

From source file:org.multibit.file.FileHandler.java

public static byte[] read(File file) throws IOException {
    if (file == null) {
        throw new IllegalArgumentException("File must be provided");
    }//from   www.j a va2 s .  co  m

    if (file.length() > MAX_FILE_SIZE) {
        throw new IOException("File '" + file.getAbsolutePath() + "' is too large to input");
    }

    byte[] buffer = new byte[(int) file.length()];
    InputStream ios = null;
    try {
        ios = new FileInputStream(file);
        if (ios.read(buffer) == -1) {
            throw new IOException("EOF reached while trying to read the whole file");
        }
    } finally {
        try {
            if (ios != null) {
                ios.close();
            }
        } catch (IOException e) {
            log.error(e.getClass().getName() + " " + e.getMessage());
        }
    }

    return buffer;
}

From source file:com.kurento.kmf.test.base.GridBrowserMediaApiTest.java

private void startNodes() throws InterruptedException {
    countDownLatch = new CountDownLatch(nodes.size());

    for (final Node n : nodes) {
        Thread t = new Thread() {
            public void run() {
                try {
                    startNode(n);// w  ww  .jav a2  s  .  c  om
                } catch (IOException e) {
                    log.error("Exception starting node {} : {}", n.getAddress(), e.getClass());
                }
            }
        };
        t.start();
    }

    if (!countDownLatch.await(TIMEOUT_NODE, TimeUnit.SECONDS)) {
        Assert.fail("Timeout waiting nodes (" + TIMEOUT_NODE + " seconds)");
    }
}

From source file:org.mxhero.engine.plugin.attachmentlink.alcommand.internal.domain.Attach.java

public void buildMd5Checksum(InputStream inputStream) {
    String checksum = "";
    try {//from ww  w  .  j ava2  s .c om
        checksum = DigestUtils.md5Hex(inputStream);
        setMd5Checksum(checksum);
    } catch (IOException e) {
        log.error("Could not build the Checksum code for the file. Attach: " + getFileName() + " - "
                + e.getClass().getName() + " - " + e.getMessage());
        throw new RuntimeException("Could not obtain md5 checksum from file " + getFileName());
    }
}

From source file:com.mashape.galileo.agent.network.AnalyticsRetryHandler.java

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

    Args.notNull(exception, "Exception parameter");
    Args.notNull(context, "HTTP context");

    if (executionCount > this.retryCount) {
        return false;
    }//from w w w  . j av a 2 s.  c om

    if (this.nonRetriableClasses.contains(exception.getClass())) {
        return false;
    } else {
        for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
            if (rejectException.isInstance(exception)) {
                return false;
            }
        }
    }

    if (exception instanceof NoHttpResponseException | exception instanceof SocketException
            | exception instanceof NoHttpResponseException) {
        LOGGER.warn(String.format("flush rquest failed, Agent will try to resend the request. reson: (%s)",
                exception.getMessage()));
        return true;
    }

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    if (!clientContext.isRequestSent()) {
        LOGGER.debug("Agent will try to resend the request.");
        return true;
    }

    return false;
}

From source file:it.evilsocket.dsploit.core.UpdateService.java

public static boolean isGemUpdateAvailable() {

    try {//from  w w  w  .  j  av  a2s .c  o m
        synchronized (mGemUploadParser) {
            GemParser.RemoteGemInfo[] gemInfoArray = mGemUploadParser.parse();
            ArrayList<GemParser.RemoteGemInfo> gemsToUpdate = new ArrayList<GemParser.RemoteGemInfo>();

            if (gemInfoArray.length == 0)
                return false;

            String format = String.format("%s/lib/ruby/gems/1.9.1/specifications/%%s-%%s-arm-linux.gemspec",
                    System.getRubyPath());

            for (GemParser.RemoteGemInfo gemInfo : gemInfoArray) {
                File f = new File(String.format(format, gemInfo.name, gemInfo.version));
                if (!f.exists() || f.lastModified() < gemInfo.uploaded.getTime()) {
                    Logger.debug(String.format("'%s' %s", f.getAbsolutePath(),
                            (f.exists() ? "is old" : "does not exists")));
                    gemsToUpdate.add(gemInfo);
                }
            }

            if (gemsToUpdate.size() == 0)
                return false;

            mGemUploadParser.setOldGems(gemsToUpdate.toArray(new GemParser.RemoteGemInfo[gemsToUpdate.size()]));
            return true;
        }
    } catch (IOException e) {
        Logger.warning(e.getClass() + ": " + e.getMessage());
    } catch (JSONException e) {
        System.errorLogging(e);
    }
    return false;
}

From source file:photosharing.api.conx.UploadFileDefinition.java

/**
 * get nonce as described with nonce <a href="http://ibm.co/1fG83gY">Get a
 * Cryptographic Key</a>//from  w  w  w  .j  av a2 s  . c om
 * 
 * @param bearer
 */
private String getNonce(String bearer, HttpServletResponse response) {
    String nonce = "";

    // Build the Request
    Request get = Request.Get(getNonceUrl());
    get.addHeader("Authorization", "Bearer " + bearer);

    try {
        Executor exec = ExecutorUtil.getExecutor();
        Response apiResponse = exec.execute(get);
        HttpResponse hr = apiResponse.returnResponse();

        /**
         * Check the status codes and if 200, convert to String
         */
        int code = hr.getStatusLine().getStatusCode();

        // Session is no longer valid or access token is expired
        if (code == HttpStatus.SC_FORBIDDEN) {
            response.sendRedirect("./api/logout");
        }

        // User is not authorized
        else if (code == HttpStatus.SC_UNAUTHORIZED) {
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        }

        else if (code == HttpStatus.SC_OK) {
            InputStream in = hr.getEntity().getContent();
            nonce = IOUtils.toString(in);
        }

    } catch (IOException e) {
        response.setHeader("X-Application-Error", e.getClass().getName());
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        logger.severe("IOException " + e.toString());
    }

    return nonce;
}

From source file:com.clustercontrol.ping.util.ReachAddressFping.java

/**
 * ????????????//from   ww  w .j a v  a 2 s . c om
 * 
 * @param info
 * @return PING
 */
public boolean isReachable(HashSet<String> hosts, int version) {

    Process process = null;//fping
    int m_exitValue = 0; //fping?

    String fpingPath;
    if (version == 6) {
        fpingPath = PingProperties.getFping6Path();
    } else {
        fpingPath = PingProperties.getFpingPath();
    }
    String cmd[] = FpingCommand.getCommand(fpingPath, hosts, m_sentCount, m_sentInterval, m_timeout, m_bytes);

    try {
        process = Runtime.getRuntime().exec(cmd);

        if (process != null) {
            //???
            StreamReader errStreamReader = new StreamReader(process.getErrorStream());
            errStreamReader.start();
            StreamReader inStreamReader = new StreamReader(process.getInputStream());
            inStreamReader.start();

            //            
            m_exitValue = process.waitFor();

            //?

            inStreamReader.join();
            m_resultMsg = inStreamReader.getResult();
            m_log.debug("isReachable() STDOUT :" + inStreamReader.getResult().toString());

            errStreamReader.join();
            m_errMsg = errStreamReader.getResult();
            m_log.debug("isReachable() STDERR :" + errStreamReader.getResult().toString());

        }
    } catch (IOException e) {
        m_errMsg = new ArrayList<String>();
        m_errMsg.add(e.getMessage());
        m_log.warn("isReachable() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        return false;

    } catch (InterruptedException e) {
        m_errMsg = new ArrayList<String>();
        m_errMsg.add(e.getMessage());
        m_log.warn("isReachable() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        return false;
    } finally {
        if (process != null) {
            process.destroy();
        }
    }
    if (m_exitValue == 0 || m_exitValue == 1) {
        m_log.debug("exit value = " + m_exitValue);

        //fping??0????
        //fping??unreachable??1??????1???
        return true;
    } else {
        String errMsg = "fping exit value is not 0 or 1. exit value = " + m_exitValue;
        m_log.info(errMsg);
        for (int j = 0; j < cmd.length; j++) {
            m_log.info("cmd[" + j + "] = " + cmd[j]);
        }

        m_errMsg = new ArrayList<String>();
        m_errMsg.add(errMsg);

        //fping??!0 or !1???
        return false;
    }
}

From source file:org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender.java

@Override
public void handleSendMessage(Message aMessage) throws IllegalArgumentException, IOException {
    final HttpMessage httpMessage = (HttpMessage) aMessage;
    try {/*from w  ww  .ja v  a 2s.c o m*/
        final ModeRedirectionValidator redirectionValidator = new ModeRedirectionValidator();
        boolean followRedirects = getButtonFollowRedirects().isSelected();
        if (followRedirects) {
            getDelegate().sendAndReceive(httpMessage,
                    HttpRequestConfig.builder().setRedirectionValidator(redirectionValidator).build());
        } else {
            getDelegate().sendAndReceive(httpMessage, false);
        }

        EventQueue.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                if (!httpMessage.getResponseHeader().isEmpty()) {
                    // Indicate UI new response arrived
                    responsePanel.updateContent();

                    if (!followRedirects) {
                        persistAndShowMessage(httpMessage);
                    } else if (!redirectionValidator.isRequestValid()) {
                        View.getSingleton().showWarningDialog(
                                Constant.messages.getString("manReq.outofscope.redirection.warning",
                                        redirectionValidator.getInvalidRedirection()));
                    }
                }
            }
        });

        ZapGetMethod method = (ZapGetMethod) httpMessage.getUserObject();
        notifyPersistentConnectionListener(httpMessage, null, method);

    } catch (final HttpMalformedHeaderException mhe) {
        throw new IllegalArgumentException("Malformed header error.", mhe);

    } catch (final UnknownHostException uhe) {
        throw new IOException("Error forwarding to an Unknown host: " + uhe.getMessage(), uhe);

    } catch (final SSLException sslEx) {
        throw sslEx;
    } catch (final IOException ioe) {
        throw new IOException("IO error in sending request: " + ioe.getClass() + ": " + ioe.getMessage(), ioe);

    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.cruk.util.CommandLineUtility.java

/**
 * Runs the utility taking care of opening and closing the output writer.
 *//* w w w  .j  ava2s.  c om*/
public void execute() {
    if (outputFilename == null) {
        out = System.out;
    } else {
        try {
            out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename)));
        } catch (IOException e) {
            error("Error creating file " + outputFilename);
        }
    }

    try {
        run();
        out.flush();
    } catch (Exception e) {
        e.printStackTrace();
        error("Error: " + e.getClass().getName() + " " + e.getMessage());
    } finally {
        closeOutputStream();
    }
}