Example usage for java.io IOException getMessage

List of usage examples for java.io IOException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.github.drochetti.javassist.maven.ClassnameExtractor.java

/**
 * Wrapping passed iterator (as reference) of class file names and extract full qualified class name on
 * {@link Iterator#next()}./*  w  w w .j  av a 2s .  com*/
 * <p>
 * It is possible that {@link Iterator#hasNext()} returns <code>true</code>
 * and {@link Iterator#next()} returns <code>null</code>.
 * 
 * @param parentDirectory
 * @param classFiles
 * @return iterator of full qualified class names based on passed classFiles
 *         or <code>null</code>
 * @see #extractClassNameFromFile(File, File)
 */
// DANGEROUS call by reference
public static Iterator<String> iterateClassnames(final File parentDirectory,
        final Iterator<File> classFileIterator) {
    return new Iterator<String>() {

        // @Override
        public boolean hasNext() {
            return classFileIterator == null ? false : classFileIterator.hasNext();
        }

        // @Override
        public String next() {
            final File classFile = classFileIterator.next();
            try {
                // possible returns null
                return extractClassNameFromFile(parentDirectory, classFile);
            } catch (final IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        // @Override
        public void remove() {
            classFileIterator.remove();
        }
    };
}

From source file:com.sap.nwcloudmanager.api.LogAPI.java

public static void downloadLog(final Context context, final String appId, final String logName,
        final DownloadLogResponseHandler downloadLogResponseHandler) {

    NetWeaverCloudConfig config = NetWeaverCloudConfig.getInstance();
    getHttpClient().setBasicAuth(config.getUsername(), config.getPassword());
    String[] contentTypes = { "application/x-gzip" };
    getHttpClient().get("https://monitoring." + config.getHost() + "/log/api_basic/logs/" + config.getAccount()
            + "/" + appId + "/web/" + logName, null, new BinaryHttpResponseHandler(contentTypes) {

                /*//  ww  w  . j  a  v  a2 s  .c o  m
                 * (non-Javadoc)
                 * 
                 * @see
                 * com.loopj.android.http.BinaryHttpResponseHandler#onSuccess(byte
                 * [])
                 */
                @Override
                public void onSuccess(byte[] arg0) {

                    GZIPInputStream gzis = null;

                    try {
                        gzis = new GZIPInputStream(new ByteArrayInputStream(arg0));

                        StringBuilder string = new StringBuilder();
                        byte[] data = new byte[4028];
                        int bytesRead;
                        while ((bytesRead = gzis.read(data)) != -1) {
                            string.append(new String(data, 0, bytesRead));
                        }

                        File downloadsFile = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
                        if (downloadsFile.exists()) {
                            downloadsFile = new File(
                                    context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
                                            .getAbsolutePath() + "/" + logName);
                            FileOutputStream fos = new FileOutputStream(downloadsFile);
                            fos.write(string.toString().getBytes());
                            fos.close();
                        }

                        downloadLogResponseHandler.onSuccess(downloadsFile.getAbsolutePath());

                    } catch (IOException e) {
                        Log.e(e.getMessage());
                    } finally {
                        try {
                            if (gzis != null) {
                                gzis.close();
                            }
                        } catch (IOException e) {
                        }
                    }
                }

                @Override
                public void onFailure(Throwable arg0) {
                    downloadLogResponseHandler.onFailure(arg0, arg0.getMessage());
                }

            });
}

From source file:com.zack6849.alphabot.api.Utils.java

public static String getTitle(String link) {
    String response = "";
    try {//  w  w w  .j ava2  s.  c  om
        HttpURLConnection conn = (HttpURLConnection) new URL(link).openConnection();
        conn.addRequestProperty("User-Agent", USER_AGENT);
        String type = conn.getContentType();
        int length = conn.getContentLength() / 1024;
        response = String.format("HTTP %s: %s", conn.getResponseCode(), conn.getResponseMessage());
        String info;
        if (type.contains("text") || type.contains("application")) {
            Document doc = Jsoup.connect(link).userAgent(USER_AGENT).followRedirects(true).get();
            String title = doc.title() == null || doc.title().isEmpty() ? "No title found!" : doc.title();
            info = String.format("%s - (Content Type: %s Size: %skb)", title, type, length);
            return info;
        }
        info = String.format("Content Type: %s Size: %skb", type, length);
        return info;

    } catch (IOException ex) {
        if (ex.getMessage().contains("UnknownHostException")) {
            return Colors.RED + "Unknown hostname!";
        }
        return response.isEmpty() ? Colors.RED + "An error occured" : response;
    }
}

From source file:com.zack6849.alphabot.api.Utils.java

public static String checkMojangServers() {
    String returns = null;/*  w w w.j a  va2 s  .  c  o m*/
    try {
        URL url;
        url = new URL("http://status.mojang.com/check");
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String result;
        while ((result = reader.readLine()) != null) {
            String a = result.replace("red", Colors.RED + "Offline" + Colors.NORMAL)
                    .replace("green", Colors.GREEN + "Online" + Colors.NORMAL).replace("[", "")
                    .replace("]", "");
            returns = a.replace("{", "").replace("}", "").replace(":", " is currently ").replace("\"", "")
                    .replaceAll(",", ", ");
        }
        reader.close();
    } catch (IOException e) {
        if (e.getMessage().contains("503")) {
            returns = "The minecraft status server is temporarily unavailable, please try again later";
        }
        if (e.getMessage().contains("404")) {
            returns = "Uhoh, it would appear as if the status page has been removed or relocated >_>";
        }

    }
    return returns;
}

From source file:de.ee.hezel.PDFCompareMain.java

/**
 * delete the old difference image and create the output path if not exists
 * /*  w w  w. ja  v a2s  .  c o m*/
 * @param targetPath
 */
public static void checkOutputPath(File targetPath) {

    if (targetPath != null && targetPath.exists()) {
        // shows a window which asks you if the old content of the output directory should be deleted
        //          int confirmation = JOptionPane.showConfirmDialog(null, "Output directory not empty. Delete all contents of '" + targetPath + "' and continue?", "Confirmation", JOptionPane.YES_NO_OPTION);
        //          if (confirmation == JOptionPane.NO_OPTION)
        //              return;

        try {
            FileUtils.deleteDirectory(targetPath);
        } catch (IOException e1) {
            throw new RuntimeException("Unable to clean output directory: " + e1.getMessage(), e1);
        }
        targetPath.mkdirs();
    }
    if (!targetPath.exists())
        targetPath.mkdir();
}

From source file:com.github.koraktor.steamcondenser.servers.packets.SteamPacketFactory.java

/**
 * Reassembles the data of a split and/or compressed packet into a single
 * packet object/*from   ww w.  j  a v  a  2s .  c  o  m*/
 *
 * @param splitPackets An array of packet data
 * @param isCompressed whether the data of this packet is compressed
 * @param uncompressedSize The size of the decompressed packet data
 * @param packetChecksum The CRC32 checksum of the decompressed
 *        packet data
 * @throws SteamCondenserException if decompressing the packet data fails
 * @throws PacketFormatException if the calculated CRC32 checksum does not
 *         match the expected value
 * @return SteamPacket The reassembled packet
 * @see SteamPacketFactory#getPacketFromData
 */
public static SteamPacket reassemblePacket(ArrayList<byte[]> splitPackets, boolean isCompressed,
        int uncompressedSize, int packetChecksum) throws SteamCondenserException {
    byte[] packetData, tmpData;
    packetData = new byte[0];

    for (byte[] splitPacket : splitPackets) {
        tmpData = packetData;
        packetData = new byte[tmpData.length + splitPacket.length];
        System.arraycopy(tmpData, 0, packetData, 0, tmpData.length);
        System.arraycopy(splitPacket, 0, packetData, tmpData.length, splitPacket.length);
    }

    if (isCompressed) {
        try {
            ByteArrayInputStream stream = new ByteArrayInputStream(packetData);
            stream.read();
            stream.read();
            BZip2CompressorInputStream bzip2 = new BZip2CompressorInputStream(stream);
            byte[] uncompressedPacketData = new byte[uncompressedSize];
            bzip2.read(uncompressedPacketData, 0, uncompressedSize);

            CRC32 crc32 = new CRC32();
            crc32.update(uncompressedPacketData);
            int crc32checksum = (int) crc32.getValue();

            if (crc32checksum != packetChecksum) {
                throw new PacketFormatException("CRC32 checksum mismatch of uncompressed packet data.");
            }
            packetData = uncompressedPacketData;
        } catch (IOException e) {
            throw new SteamCondenserException(e.getMessage(), e);
        }
    }

    tmpData = packetData;
    packetData = new byte[tmpData.length - 4];
    System.arraycopy(tmpData, 4, packetData, 0, tmpData.length - 4);

    return SteamPacketFactory.getPacketFromData(packetData);
}

From source file:io.github.retz.executor.FileManager.java

private static void fetchHTTPFile(String file, String dest) throws IOException {
    URL url = new URL(file);

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");

    conn.setDoOutput(true);//from w ww .  ja  v a 2  s .  c  om
    java.nio.file.Path path = Paths.get(file).getFileName();
    if (path == null) {
        throw new FileNotFoundException(file);
    }
    String filename = path.toString();
    InputStream input = null;
    try (FileOutputStream output = new FileOutputStream(dest + "/" + filename)) {
        input = conn.getInputStream();
        byte[] buffer = new byte[65536];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }
    } catch (IOException e) {
        LOG.debug(e.getMessage());
        throw e;
    } finally {
        if (input != null)
            input.close();
    }
    conn.disconnect();
    LOG.info("Download finished: {}", file);
}

From source file:com.nanosheep.bikeroute.parser.MapQuestParser.java

/**
 * Convert an inputstream to a string.//from   w ww.  j av  a 2  s.c om
 * @param input inputstream to convert.
 * @return a String of the inputstream.
 */

private static String convertStreamToString(final InputStream input) {
    final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
    final StringBuilder sBuf = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sBuf.append(line);
        }
    } catch (IOException e) {
        Log.e(e.getMessage(), "MQ parser, stream2string");
    } finally {
        try {
            input.close();
        } catch (IOException e) {
            Log.e(e.getMessage(), "MQ parser, stream2string");
        }
    }
    return sBuf.toString();
}

From source file:info.magnolia.importexport.Bootstrapper.java

/**
 * Bootstrap the array of files.//from  w ww .j av  a2  s  .c  o m
 */
private static boolean bootstrapFiles(String repositoryName, File[] files) {
    try {
        for (int k = 0; k < files.length; k++) {
            File xmlFile = files[k];
            log.debug("Importing {}", xmlFile);
            DataTransporter.executeBootstrapImport(xmlFile, repositoryName);
        }
    } catch (IOException ioe) {
        log.error(ioe.getMessage(), ioe);
    } catch (OutOfMemoryError e) {
        int maxMem = (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024);
        int needed = Math.max(256, maxMem + 128);
        log.error("Unable to complete bootstrapping: out of memory.\n"
                + "{} MB were not enough, try to increase the amount of memory available by adding the -Xmx{}m parameter to the server startup script.\n"
                + "You will need to completely remove the Magnolia webapp before trying again",
                Integer.toString(maxMem), Integer.toString(needed));
        return false;
    }
    return true;
}

From source file:com.ms.commons.utilities.HttpClientUtils.java

/**
 * byte[]??method????getResponseBodyAsStream
 * //from  w w w.j a v a 2 s  .  co m
 * @param method
 * @return
 */
public static byte[] getResponseBodyAsByte(HttpMethod method) {
    init();
    InputStream inputStream = null;
    try {
        inputStream = getResponseBodyAsStream(method, null, null);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(inputStream, baos);
        return baos.toByteArray();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(inputStream);
        method.releaseConnection();
    }
    return new byte[] {};
}