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:com.boundlessgeo.wps.grass.GrassProcesses.java

@DescribeProcess(title = "GRASS Version", description = "Retreive the version of GRASS used for computation")
@DescribeResult(description = "Version")
public static String version() {
    if (EXEC == null) {
        return "unavailable";
    }/*from   w w w . j  a va2  s  . co m*/
    CommandLine cmd = new CommandLine(EXEC);
    cmd.addArgument("-v");

    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
    executor.setWatchdog(watchdog);
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        executor.setStreamHandler(new PumpStreamHandler(outputStream));

        LOGGER.info("exec: " + cmd.toString());
        int exitValue = executor.execute(cmd);
        return outputStream.toString();
    } catch (ExecuteException huh) {
        return "exit code: " + huh.getExitValue() + " (" + huh.getMessage() + ")";
    } catch (IOException e) {
        return "unavailable: " + e.getClass().getSimpleName() + ":" + e.getMessage();
    }
}

From source file:com.normsstuff.maps4norm.Dialogs.java

public static void loadMarks(final Activity c, final Stack<LatLng> trace) {
    File[] files = c.getDir("traces", Context.MODE_PRIVATE).listFiles();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
            && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        File ext = API8Wrapper.getExternalFilesDir(c);
        // even though we checked the external storage state, ext is still sometimes null,
        // according to Play Store crash reports
        if (ext != null) {
            File[] filesExtern = ext.listFiles();
            File[] allFiles = new File[files.length + filesExtern.length];
            System.arraycopy(files, 0, allFiles, 0, files.length);
            System.arraycopy(filesExtern, 0, allFiles, files.length, filesExtern.length);
            files = allFiles;//from   ww w  . ja v  a 2  s .c o m
        }
    }

    if (files.length == 0) {
        Toast.makeText(c, c.getString(R.string.no_files_found,
                c.getDir("traces", Context.MODE_PRIVATE).getAbsolutePath()), Toast.LENGTH_LONG).show();

    } else if (files.length == 1) {
        try {
            List<LatLng> list = Util.loadFromFile(Uri.fromFile(files[0]), (MyMapActivity) c);
            setUpDisplay((MyMapActivity) c, list);
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(c, c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                    Toast.LENGTH_LONG).show();
        }
    } else {
        AlertDialog.Builder b = new AlertDialog.Builder(c);
        b.setTitle(R.string.select_file);
        final DeleteAdapter da = new DeleteAdapter(files, (MyMapActivity) c);
        b.setAdapter(da, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                try {
                    List<LatLng> list = Util.loadFromFile(Uri.fromFile(da.getFile(which)), (MyMapActivity) c);
                    dialog.dismiss();
                    setUpDisplay((MyMapActivity) c, list);
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(c,
                            c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                            Toast.LENGTH_LONG).show();
                }
            }
        });
        b.create().show();
    }
}

From source file:com.dmitrymalkovich.android.githubanalytics.Utils.java

public static void openFeedback(Activity activity) {
    try {/*w  w  w .  ja v  a  2s.  co m*/
        throw new IOException();
    } catch (IOException e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication().getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}

From source file:com.att.android.arodatacollector.utils.AROCollectorUtils.java

/**
 * Returns a value indicating whether tcpdump is running on the
 * native shell.//from  w w  w.  j a v  a2s .c  o  m
 * 
 * @return A boolean value that is "true" if tcpdump is running on the
 *         native shell, and is "false" otherwise.
 */
public static boolean isTcpDumpRunning() {
    boolean isAroTcpDumpRunning = false;
    try {

        String line = null;
        int pid = 0; // default
        line = executePS(TCPDUMP);

        String[] rows = line.split("\\n");
        if (AROLogger.logVerbose) {
            for (int rowNum = 0; rowNum < rows.length; rowNum++) {
                AROLogger.v(TAG, "values row " + rowNum + ": " + ">>>" + rows[rowNum] + "<<<");
            }
        }
        if (rows[0].startsWith(USER)) {
            AROLogger.v(TAG, "PID should be in 2nd column in single row retrieved");
            for (int rowNum = 1; rowNum < rows.length; rowNum++) {
                final String row = rows[rowNum];
                final String[] columns = row.split("\\s+");

                if (AROLogger.logVerbose) {
                    for (int itemNum = 0; itemNum < columns.length; itemNum++) {
                        AROLogger.v(TAG, "item " + itemNum + ": " + ">>>" + columns[itemNum] + "<<<");
                    }
                }

                int pNameIndex = columns.length - 1; //process name is the last column
                String pName = columns[pNameIndex];

                if (pName != null && pName.contains(COLLECTOR)) {
                    isAroTcpDumpRunning = true;
                    break;
                }
            }
            if (AROLogger.logDebug) {
                AROLogger.d(TAG, "exiting if USER block with PID (without finding one): " + pid);
            }
        }

        if (AROLogger.logDebug) {
            AROLogger.d(TAG, "isTcpDumpRunning: " + isAroTcpDumpRunning);
        }
    } catch (IOException e) {
        AROLogger.e(TAG, e.getClass().getName() + " thrown by pstcpdump()");
    } catch (InterruptedException e) {
        AROLogger.e(TAG, e.getClass().getName() + " thrown by pstcpdump()");
    }
    return isAroTcpDumpRunning;

}

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

/**
 * Converts an IOExcpetion (not subclasses) to SocketException.
 * This is typically done to indicate to upper layers that the error
 * was a socket error rather than often more serious exceptions like
 * disk errors./*from w ww.  j av  a 2s  . co  m*/
 */
private static IOException ioeToSocketException(IOException ioe) {

    if (ioe.getClass().equals(IOException.class)) {
        // "se" could be a new class in stead of SocketException.
        final IOException se = new SocketException("Original Exception : " + ioe);
        se.initCause(ioe);
        /*
         * Change the stacktrace so that original trace is not truncated
         * when printed.
         */
        se.setStackTrace(ioe.getStackTrace());
        return se;
    }
    // otherwise just return the same exception.
    return ioe;
}

From source file:com.prowidesoftware.swift.model.mt.AbstractMT.java

/**
 * Base implementation for subclasses static parse.
 * //from  w w  w . ja  v a2 s  .c o  m
 * @since 7.7
 */
protected static SwiftMessage read(String fin) {
    SwiftParser p = new SwiftParser(fin);
    p.setLenient(true);
    try {
        return p.message();
    } catch (IOException e) {
        log.severe("An error occured while reading FIN :" + e.getClass().getName());
        log.log(Level.SEVERE, "Read exception");
        log.log(Level.SEVERE, "Read exception while parsing " + fin, e);
    }
    return null;
}

From source file:com.haoqee.chatsdk.net.Utility.java

public static String openUrl(String url, String method, BaseParameters params, List<TCMorePicture> fileList,
        TCBaseListener listener) throws HaoqeeChatException {
    String result = "";

    long timeout = 0;
    //mClient = client;
    HttpClient client = null;/*from w  w  w  .ja  v a2s  .c om*/
    try {
        HttpUriRequest request = null;
        ByteArrayOutputStream bos = null;

        if (method.equals("GET")) {
            url = url + "?" + encodeUrl(params); //Log.e("url",url);
            //Log.e("url", url);
            HttpGet get = new HttpGet(url);
            request = get;

        } else if (method.equals("POST")) {
            HttpPost post = new HttpPost(url);
            byte[] data = null;
            bos = new ByteArrayOutputStream(1024 * 50);
            if (fileList != null && fileList.size() != 0) {

                /*UrlEncodedFormEntity entity = new UrlEncodedFormEntity((List<? extends NameValuePair>) params);
                 entity.setContentEncoding("UTF-8");
                 //entity.setContentType("application/json");
                 post.setEntity(entity);*/
                Utility.paramToUpload(bos, params);
                post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY);
                //post.setHeader("Charset", "UTF-8");

                if (url.endsWith("/message/api/sendMessage")
                        && Integer.parseInt(params.getValue("typefile")) == TCMessageType.FILE) {
                    fileMessageContentToUpload(bos, fileList.get(0), listener);
                } else {
                    for (int i = 0; i < fileList.size(); i++) {
                        Utility.fileContentToUpload(bos, fileList.get(i));
                    }
                }

                bos.write(("\r\n" + END_MP_BOUNDARY).getBytes());
            } else {
                post.setHeader("Content-Type", "application/x-www-form-urlencoded");
                String postParam = encodeParameters(params);
                data = postParam.getBytes("UTF-8");
                bos.write(data);
            }
            data = bos.toByteArray();
            if (data.length > 0) {
                timeout = data.length * 1000 / (PER_SPEED * 1024);
            }
            bos.close();
            // UrlEncodedFormEntity entity = getPostParamters(params);
            ByteArrayEntity formEntity = new ByteArrayEntity(data);
            post.setEntity(formEntity);
            request = post;
        } else if (method.equals("DELETE")) {
            request = new HttpDelete(url);
        }

        client = getNewHttpClient(timeout);
        setHeader(method, request, params, url);
        HttpResponse response = client.execute(request);
        StatusLine status = response.getStatusLine();
        int statusCode = status.getStatusCode();

        if (statusCode != 200) {
            result = read(response);
            /* String err = null;
             int errCode = 0;
            try {
            JSONObject json = new JSONObject(result);
            err = json.getString("error");
            errCode = json.getInt("error_code");
            } catch (JSONException e) {
            e.printStackTrace();
            }*/
            //throw new WeiboException(String.format(err), errCode);e
        }
        // parse content stream from response
        result = read(response);
        return result;
    } catch (IOException e) {
        //Log.e("e.getClass()", e.getClass().toString());
        if (e.getClass().toString().equalsIgnoreCase("class java.nio.channels.UnresolvedAddressException")) {
            throw new HaoqeeChatException("UnresolvedAddress", e, R.string.unknown_addr);
        } else if (e.getClass().toString().equalsIgnoreCase("class java.net.UnknownHostException")) {
            throw new HaoqeeChatException("UnknownHost", e, R.string.error_host);
        } else if (e.getClass().toString()
                .equalsIgnoreCase("class org.apache.http.conn.ConnectTimeoutException")) {
            throw new HaoqeeChatException("ConnectionTimeout", e, R.string.timeout);
        } else if (e.getClass().toString().equalsIgnoreCase("class java.net.SocketTimeoutException")) {
            throw new HaoqeeChatException("SocketTimeout", e, R.string.timeout);
        }
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (client != null && client.getConnectionManager() != null) {
            client.getConnectionManager().shutdown();
            client = null;
        }
    }
    return null;
}

From source file:ch.njol.skript.Updater.java

/**
 * Must set {@link #state} to {@link UpdateState#DOWNLOAD_IN_PROGRESS} prior to calling this
 * //from w w w. j  a v  a 2s.  c o m
 * @param sender
 * @param isAutomatic
 */
static void download_i(final CommandSender sender, final boolean isAutomatic) {
    assert sender != null;
    stateLock.readLock().lock();
    try {
        if (state != UpdateState.DOWNLOAD_IN_PROGRESS)
            throw new IllegalStateException();
    } finally {
        stateLock.readLock().unlock();
    }
    Skript.info(sender, "" + m_downloading);
    //      boolean hasJar = false;
    //      ZipInputStream zip = null;
    InputStream in = null;
    try {
        final URLConnection conn = new URL(latest.get().downloadURL).openConnection();
        in = conn.getInputStream();
        assert in != null;
        FileUtils.save(in, new File(Bukkit.getUpdateFolderFile(), "Skript.jar"));
        //         zip = new ZipInputStream(conn.getInputStream());
        //         ZipEntry entry;
        ////         boolean hasAliases = false;
        //         while ((entry = zip.getNextEntry()) != null) {
        //            if (entry.getName().endsWith("Skript.jar")) {
        //               assert !hasJar;
        //               save(zip, new File(Bukkit.getUpdateFolderFile(), "Skript.jar"));
        //               hasJar = true;
        //            }// else if (entry.getName().endsWith("aliases.sk")) {
        ////               assert !hasAliases;
        ////               saveZipEntry(zip, new File(Skript.getInstance().getDataFolder(), "aliases-" + latest.get().version + ".sk"));
        ////               hasAliases = true;
        ////            }
        //            zip.closeEntry();
        //            if (hasJar)// && hasAliases)
        //               break;
        //         }
        if (isAutomatic)
            Skript.adminBroadcast("" + m_downloaded);
        else
            Skript.info(sender, "" + m_downloaded);
        stateLock.writeLock().lock();
        try {
            state = UpdateState.DOWNLOADED;
        } finally {
            stateLock.writeLock().unlock();
        }
    } catch (final IOException e) {
        stateLock.writeLock().lock();
        try {
            state = UpdateState.DOWNLOAD_ERROR;
            error.set(ExceptionUtils.toString(e));
            Skript.error(sender, m_download_error.toString());
        } finally {
            stateLock.writeLock().unlock();
        }
    } catch (final Exception e) {
        Skript.exception(e, "Error while downloading the latest version of Skript");
        stateLock.writeLock().lock();
        try {
            state = UpdateState.DOWNLOAD_ERROR;
            error.set(e.getClass().getSimpleName() + ": " + e.getLocalizedMessage());
        } finally {
            stateLock.writeLock().unlock();
        }
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (final IOException e) {
            }
        }
    }
}

From source file:de.kaiserpfalzEdv.piracc.about.AboutPageProviderImpl.java

@Override
public String getLicense() {
    String result;/*from   www .  j  a  v  a  2s.  com*/

    try {
        InputStream is = getClass().getResourceAsStream("/LICENSE.html");
        StringWriter writer = new StringWriter();
        IOUtils.copy(is, writer, "UTF-8");
        result = writer.toString();
        writer.close();
        is.close();
    } catch (IOException e) {
        LOG.error(e.getClass().getSimpleName() + " caught: " + e.getMessage(), e);

        result = i18n.get("about.license.loading-failed");
    }

    return result;
}

From source file:com.feilong.servlet.http.ResponseDownloadUtil.java

/**
 * Down load data.//w  w w .  ja  va2  s  .c  o m
 *
 * @param saveFileName
 *            the save file name
 * @param inputStream
 *            the input stream
 * @param contentLength
 *            the content length
 * @param request
 *            the request
 * @param response
 *            the response
 */
private static void downLoadData(String saveFileName, InputStream inputStream, Number contentLength,
        HttpServletRequest request, HttpServletResponse response) {
    Date beginDate = new Date();
    String length = FileUtil.formatSize(contentLength.longValue());
    LOGGER.info("begin download~~,saveFileName:[{}],contentLength:[{}]", saveFileName, length);
    try {
        OutputStream outputStream = response.getOutputStream();
        IOWriteUtil.write(inputStream, outputStream);
        if (LOGGER.isInfoEnabled()) {
            String pattern = "end download,saveFileName:[{}],contentLength:[{}],time use:[{}]";
            LOGGER.info(pattern, saveFileName, length, formatDuration(beginDate));
        }
    } catch (IOException e) {
        /*
         * ?,  ClientAbortException , ?,????, ,.
         * ??, ??
         * ?,???...???,
         * ?, KILL?, ,?? ClientAbortException.
         */
        //ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
        final String exceptionName = e.getClass().getName();

        if (StringUtils.contains(exceptionName, "ClientAbortException")
                || StringUtils.contains(e.getMessage(), "ClientAbortException")) {
            String pattern = "[ClientAbortException],maybe user use Thunder soft or abort client soft download,exceptionName:[{}],exception message:[{}] ,request User-Agent:[{}]";
            LOGGER.warn(pattern, exceptionName, e.getMessage(), RequestUtil.getHeaderUserAgent(request));
        } else {
            LOGGER.error("[download exception],exception name: " + exceptionName, e);
            throw new UncheckedIOException(e);
        }
    }
}