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:Main.java

static String validGet(URL url) throws IOException {
    String html = "";
    HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.STRICT_HOSTNAME_VERIFIER;
    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
    // TODO ensure HttpsURLConnection.setDefaultSSLSocketFactory isn't
    // required to be reset like hostnames are
    HttpURLConnection conn = null;
    try {//from ww w  . j  a  v a2  s  .c om
        conn = (HttpURLConnection) url.openConnection();
        conn.setUseCaches(false);
        conn.setRequestMethod("GET");
        setBasicAuthentication(conn, url);
        int status = conn.getResponseCode();
        if (status != 200) {
            Logd(TAG, "Failed to get from server, returned code: " + status);
            throw new IOException("Get failed with error code " + status);
        } else {
            InputStreamReader in = new InputStreamReader(conn.getInputStream());
            BufferedReader br = new BufferedReader(in);
            String decodedString;
            while ((decodedString = br.readLine()) != null) {
                html += decodedString;
            }
            in.close();
        }
    } catch (IOException e) {
        Logd(TAG, "Failed to get from server: " + e.getMessage());
    }
    if (conn != null) {
        conn.disconnect();
    }
    return html;
}

From source file:org.dataconservancy.ui.it.support.HttpRequestLogger.java

public static void logRequest(HttpRequest req) {
    StringBuilder msg = new StringBuilder("HTTP Request:\n");
    msg.append(req.getRequestLine().toString()).append("\n");
    for (Header h : req.getAllHeaders()) {
        msg.append(h.getName()).append(": ").append(h.getValue()).append("\n");
    }//  w  ww.j a v  a 2  s.  c  o  m

    if (req instanceof HttpPost) {
        HttpEntity entity = ((HttpPost) req).getEntity();

        if (entity instanceof MultipartEntity) {
            msg.append("** Cannot display multipart entity bodies! **");
        } else {
            try {
                msg.append(IOUtils.toString(entity.getContent(), "UTF-8"));
                msg.append("\n");
            } catch (IOException e) {
                msg.append("** Cannot display entity body: ").append(e.getMessage());
            }
        }
    }

    msg.append("\n\n");
    LOG.error(msg.toString());
}

From source file:com.incapture.rapgen.output.OutputWriter.java

/**
 * Some files are composed of multiple templates. So the map passed in here is filename to template order to template.
 * E.g. "file.txt"->1->"some code" "file.txt"->2->"other code" and so on.
 *
 * @param rootFolder//ww w  . j av a  2s. c  om
 * @param pathToTemplate
 */
public static void writeMultiPartTemplates(String rootFolder,
        Map<String, Map<String, StringTemplate>> pathToTemplate) {
    // For each file, dump the templates
    for (Map.Entry<String, Map<String, StringTemplate>> entry : pathToTemplate.entrySet()) {
        File file = new File(rootFolder, entry.getKey());
        file.getParentFile().mkdirs();

        BufferedWriter bow = null;
        try {
            bow = new BufferedWriter(new FileWriter(file));
            Set<String> sections = entry.getValue().keySet();
            SortedSet<String> sorted = new TreeSet<String>();
            sorted.addAll(sections);
            for (String sec : sorted) {
                bow.write(entry.getValue().get(sec).toString());
                bow.newLine();
            }
            bow.close();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        } finally {
            if (bow != null) {
                try {
                    bow.close();
                } catch (IOException e) {
                    System.err.println("Error closing output stream: " + ExceptionToString.format(e));
                }
            }
        }
    }
}

From source file:it.geosolutions.mariss.wps.ppio.OutputResourcesPPIO.java

private static void addToZip(File f, ZipOutputStream zos) {

    FileInputStream in = null;/*from  w ww  . java 2s  . c o  m*/
    try {
        in = new FileInputStream(f);
        zos.putNextEntry(new ZipEntry(f.getName()));
        IOUtils.copy(in, zos);
        zos.closeEntry();
    } catch (IOException e) {
        LOGGER.severe(e.getMessage());
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                LOGGER.severe(e.getMessage());
            }
        }
    }
}

From source file:Main.java

/**
 * Load lines of strings from a file//from   w  w  w  .  j a v  a2s  . com
 *
 * @param path     the path to the file
 * @param fileName the file name
 * @return an list of string lines
 */
public static List<String> loadFromFile(File path, String fileName) {

    ArrayList<String> arrayList = new ArrayList<>();
    if (path.exists()) {

        File file = new File(path, fileName);

        BufferedReader bufferedReader = null;
        InputStreamReader isr = null;
        FileInputStream fis = null;
        try {

            fis = new FileInputStream(file);
            isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
            bufferedReader = new BufferedReader(isr);

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                arrayList.add(line);
            }

            return arrayList;

        } catch (IOException ignored) {
        } finally {
            if (isr != null) {
                try {
                    isr.close();
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
        }
    }

    return null;
}

From source file:com.sec.ose.osi.UIMain.java

private static boolean isRunning() {
    log.debug("Running Test...");
    String execCMD = "";
    String protexStr = "";
    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.indexOf("win") >= 0) {
        // windows
        execCMD = "TASKLIST /V /FO CSV /FI \"IMAGENAME eq javaw.exe\" /NH";
        protexStr = "osit";
    } else if (osName.indexOf("nix") >= 0 || osName.indexOf("nux") >= 0) {
        execCMD = "ps -ef";
        protexStr = "java -jar ./lib/" + OSIT_JAR_FILE_NAME;
    } else {//from   www .ja va  2  s . c o m
        JOptionPane.showMessageDialog(null, osName + " is not supported. The program will be closed.", "Error",
                JOptionPane.ERROR_MESSAGE);
        //         System.exit(-1);
    }

    InputStreamReader isr = null;
    try {
        Process p = Runtime.getRuntime().exec(execCMD);
        isr = new InputStreamReader(p.getInputStream(), "UTF-8");
        BufferedReader reader = new BufferedReader(isr);

        String str = null;
        int count = 0;
        while ((str = reader.readLine()) != null) {
            log.debug("### ONLY ONE OSI PROCESS CHECK : " + str.toLowerCase());
            if (str.toLowerCase().contains(protexStr.toLowerCase())) {
                if (++count > 1) {
                    reader.close();
                    return true;
                }
            }
        }
    } catch (IOException e1) {
        log.warn(e1.getMessage());
    } finally {
        try {
            if (isr != null) {
                isr.close();
            }
        } catch (Exception e) {
            log.debug(e);
        }
    }
    return false;
}

From source file:com.aurel.track.admin.customize.scripting.ScriptUtil.java

/**
 * Read the parameter script line by line
 * @param content//from  w ww .  ja  v a  2s.  c o m
 * @return
 */
public static List<String> getParameterDataLines(String content) {
    List<String> lines = new ArrayList<String>();
    if (content != null) {
        BufferedReader reader = new BufferedReader(new StringReader(content));
        try {
            String line = null;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException e) {
            LOGGER.warn("Getting the line failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                LOGGER.warn("Closing the stream failed with " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    return lines;
}

From source file:com.dotmarketing.util.UpdateUtil.java

/**
 * Loads the update.properties file//from   www.  j  a v  a 2  s.  co m
 *
 * @return the update.properties properties
 */
private static Properties loadUpdateProperties() {

    Properties props = new Properties();

    ClassLoader cl = UpdateUtil.class.getClassLoader();
    InputStream is = cl.getResourceAsStream(Constants.PROPERTIES_UPDATE_FILE_LOCATION);
    try {
        props.load(is);
    } catch (IOException e) {
        Logger.debug(UpdateUtil.class, "IOException: " + e.getMessage(), e);
    }

    return props;
}

From source file:com.milang.torparknow.GreenParkingApp.java

/**
 * Load JSONObject from javascript file// ww  w . j a v a2 s  .c o m
 * @param context
 * @return
 */
public static JSONObject readJson(Context context) {
    InputStream is = null;
    String jsonString = null;
    JSONObject json = null;

    Log.i(TAG, "Reading JSON...");

    try {
        is = context.getResources().openRawResource(R.raw.carparks);
        byte[] reader = new byte[is.available()];
        while (is.read(reader) != -1) {
        }
        jsonString = "{\"carparks\": " + new String(reader) + "}";
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }

    try {
        json = new JSONObject(jsonString);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }

    return json;
}

From source file:StringUtils.java

/**
 * Decode a string using Base64 encoding.
 *
 * @param str//from ww w .  jav a2  s  .  c o  m
 * @return String
 */
public static String decodeString(String str) {
    sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
    try {
        return new String(dec.decodeBuffer(str));
    } catch (IOException io) {
        throw new RuntimeException(io.getMessage(), io.getCause());
    }
}