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

private static String[][] readMatrix(final String arg) throws IOException {
    try {/*from  www  .  j  a  v a2s .c  o  m*/
        if (new File(arg).isFile())
            return Matrix.read(new FileInputStream(arg));
        else
            return Matrix.read(new ByteArrayInputStream(arg.getBytes()));
    } catch (final IOException e) {
        throw new IOException(arg + NEW_LINE + e.getMessage());
    } catch (final IllegalArgumentException e) {
        throw new IllegalArgumentException(arg + NEW_LINE + e.getMessage());
    } catch (final NullPointerException e) {
        throw new NullPointerException(arg + NEW_LINE + e.getMessage());
    }
}

From source file:gov.nih.nci.caintegrator.application.lists.UserListGenerator.java

public static List<String> generateList(FileItem formFile) throws IOException {

    List<String> tempList = new ArrayList<String>();

    if ((formFile != null) && (formFile.getName().endsWith(".txt") || formFile.getName().endsWith(".TXT"))) {

        try {//  ww  w . j av  a  2s  .  c  om
            InputStream stream = formFile.getInputStream();
            String inputLine = null;
            BufferedReader inFile = new BufferedReader(new InputStreamReader(stream));

            do {
                inputLine = inFile.readLine();

                if (inputLine != null) {
                    if (isAscii(inputLine)) { // make sure all data is ASCII                                                        
                        tempList.add(inputLine);
                    }
                } else {
                    System.out.println("null line");
                    while (tempList.contains("")) {
                        tempList.remove("");
                    }
                    inFile.close();
                    break;
                }

            } while (true);
        } catch (EOFException eof) {
            logger.error("Errors when reading empty lines in file:" + eof.getMessage());
        } catch (IOException ex) {
            logger.error("Errors when uploading file:" + ex.getMessage());
        }

    }

    return tempList;

}

From source file:apim.restful.importexport.utils.ArchiveGeneratorUtil.java

/**
 * Generate archive file/*from w w  w . j a  v a2 s. c  om*/
 *
 * @param directoryToZip Location of the archive
 * @param fileList       List of files to be included in the archive
 * @throws APIExportException If an error occurs while adding files to the archive
 */
private static void writeArchiveFile(File directoryToZip, List<File> fileList) throws APIExportException {

    FileOutputStream fileOutputStream = null;
    ZipOutputStream zipOutputStream = null;

    try {
        fileOutputStream = new FileOutputStream(directoryToZip.getPath() + ".zip");
        zipOutputStream = new ZipOutputStream(fileOutputStream);
        for (File file : fileList) {
            if (!file.isDirectory()) {
                addToArchive(directoryToZip, file, zipOutputStream);
            }
        }

    } catch (IOException e) {
        log.error("I/O error while adding files to archive" + e.getMessage());
        throw new APIExportException("I/O error while adding files to archive", e);
    } finally {
        IOUtils.closeQuietly(zipOutputStream);
        IOUtils.closeQuietly(fileOutputStream);
    }
}

From source file:com.microsoft.alm.client.utils.JsonHelper.java

public static <T> T deserializeResponce(final HttpMethodBase response, final TypeReference<T> genericType) {
    try {/*from   w ww.ja  v  a 2  s  . co  m*/
        final byte[] input = response.getResponseBody();

        if (input == null || input.length == 0) {
            return null;
        } else {
            if (isArrayType(genericType)) {
                final JavaType rootType = objectMapper.getTypeFactory().constructParametricType(
                        VssJsonCollectionWrapper.class, objectMapper.constructType(genericType.getType()));

                final VssJsonCollectionWrapper<T> result = objectMapper.readValue(input, rootType);
                return result.getValue();
            } else {
                return objectMapper.readValue(input, genericType);
            }
        }
    } catch (final IOException e) {
        log.error(e.getMessage(), e);
        throw new VssServiceException(e.getMessage(), e);
    } finally {
        response.releaseConnection();
    }
}

From source file:Zip.java

/**
 * Reads a GZIP file and dumps the contents to the console.
 *//*  w w  w.  j a v a 2  s . c o m*/
public static void readGZIPFile(String fileName) {
    // use BufferedReader to get one line at a time
    BufferedReader gzipReader = null;
    try {
        // simple loop to dump the contents to the console
        gzipReader = new BufferedReader(
                new InputStreamReader(new GZIPInputStream(new FileInputStream(fileName))));
        while (gzipReader.ready()) {
            System.out.println(gzipReader.readLine());
        }
        gzipReader.close();
    } catch (FileNotFoundException fnfe) {
        System.out.println("The file was not found: " + fnfe.getMessage());
    } catch (IOException ioe) {
        System.out.println("An IOException occurred: " + ioe.getMessage());
    } finally {
        if (gzipReader != null) {
            try {
                gzipReader.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:es.deustotech.piramide.utils.net.JSONParser.java

public static Vector<Point> parseFromUrl(HttpEntity httpEntity) {
    if (httpEntity != null) {
        InputStream inStream;// w  w w . j  ava 2s .  com
        try {
            inStream = httpEntity.getContent();
            result = convertStreamToString(inStream);
            points = new Vector<Point>();
            final JSONObject jsonObj = new JSONObject(result);

            final JSONObject result = jsonObj.getJSONObject(Constants.JSON_RESPONSE_DATA);

            //show 8 results
            for (int i = 0; i < 8; i++) {
                final JSONObject resultAux = (JSONObject) result.getJSONArray(Constants.JSON_RESULTS).get(i);
                //               final JSONObject phoneAux    = (JSONObject) resultAux.getJSONArray(Constants.JSON_PHONE_NUMBERS).get(0);

                final Point point = new Point(resultAux.getString(Constants.JSON_TITLE),
                        resultAux.getString(Constants.JSON_STREET), resultAux.getString(Constants.JSON_LAT),
                        resultAux.getString(Constants.JSON_LNG)

                /*new PhoneNumbers(phoneAux.getString(Constants.JSON_TYPE), 
                phoneAux.getString(Constants.JSON_NUMBER)), 
                resultAux.getString(Constants.JSON_CITY), 
                resultAux.getString(Constants.JSON_TITLE), 
                resultAux.getString(Constants.JSON_REGION), 
                resultAux.getString(Constants.JSON_TITLE_NO_FORMATTING), 
                resultAux.getString(Constants.JSON_STREET), 
                resultAux.getJSONArray(Constants.JSON_ADDRESS_LINES).getString(0), 
                resultAux.getString(Constants.JSON_COUNTRY), 
                resultAux.getString(Constants.JSON_LAT), 
                resultAux.getString(Constants.JSON_LNG),
                resultAux.getString(Constants.JSON_TO_HERE), 
                resultAux.getString(Constants.JSON_FROM_HERE)*/);

                points.add(point);
            }

            //            final JSONObject phoneAux    = (JSONObject) result.getJSONArray(Constants.JSON_PHONE_NUMBERS).get(0);

            /*
            Log.i(Constants.TAG, "<jsonobject>\n" + jsonObj.toString() + "\n</jsonobject>");
                    
            final JSONArray nameArray    = jsonObj.names();
            final JSONArray valArray    = jsonObj.toJSONArray(nameArray);
                    
            for(int i=0; i<valArray.length(); i++) {
               Log.e(Constants.TAG, "<jsonname" + i + ">\n" + nameArray.getString(i) + "\n</jsonname" + i + ">\n" 
             + "<jsonvalue" + i + ">\n" + valArray.getString(i) + "\n</jsonvalue" + i + ">");
            }
            jsonObj.put(Constants.SAMPLE_KEY, Constants.SAMPLE_VALUE);
                    
            Log.i(Constants.TAG, "<jsonobject>\n" + jsonObj.toString() + "\n</jsonobject>");
             */

            inStream.close();
        } catch (IllegalStateException ise) {
            Log.d(Constants.TAG, ise.getMessage());
        } catch (IOException ioe) {
            Log.d(Constants.TAG, ioe.getMessage());
        } catch (JSONException je) {
            Log.d(Constants.TAG, je.getMessage());
        }
    } // If the response does not enclose an entity, there is no need
      // to worry about connection release
    return points;
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.util.FileUtil.java

/**
 * Base64 encode the content of the given file
 *
 * @param file given file//from   w ww  .  j  a v  a  2 s. c  om
 * @return the base64 encoded file content
 */
private static String encodeFile(File file) {
    try {
        byte[] fileData = FileUtils.readFileToByteArray(file);
        return encodeDataBase64(fileData);
    } catch (IOException e) {
        throw new DatastoreException("Error reading file " + file.getName() + ":" + e.getMessage());
    }
}

From source file:com.piketec.jenkins.plugins.tpt.Publish.java

/**
 * Collects recursively all test cases by searching for "testcase_information.xml" files in
 * "rootdir". If a file could not be loaded, an error message will be printed.
 * /*w w  w  .  j  a  v a 2s  .c om*/
 * @param testDataDir
 *          The directory where TPT test data should be searched
 * @param logger
 *          to display the information
 * @return The list of parsed TPT test cases
 * 
 * @throws IOException
 *           If an error occured while parsing TPT test data
 * @throws InterruptedException
 *           If the job was interrupted
 */
public static List<Testcase> getTestcases(FilePath testDataDir, TptLogger logger)
        throws IOException, InterruptedException {
    Collection<FilePath> files = new HashSet<FilePath>();
    find(testDataDir, "testcase_information.xml", files);
    List<Testcase> testcases = new ArrayList<Testcase>(files.size());

    for (FilePath f : files) {

        try {
            Testcase tc = TestcaseParser.parseXml(f);
            testcases.add(tc);
        } catch (IOException e) {
            logger.error("File \"" + f + "\": " + e.getMessage() + "\n\r");
        }
    }

    return testcases;
}

From source file:com.urswolfer.intellij.plugin.gerrit.rest.GerritApiUtil.java

@Nullable
private static JsonElement request(@NotNull String host, @Nullable String login, @Nullable String password,
        @NotNull String path, @Nullable String requestBody, boolean post) {
    HttpMethod method = null;/*  ww w . j  a va2  s  .com*/
    try {
        method = doREST(host, login, password, path, requestBody, post);
        String resp = method.getResponseBodyAsString();
        if (method.getStatusCode() != 200) {
            String message = String.format("Request not successful. Message: %s. Status-Code: %s.",
                    method.getStatusText(), method.getStatusCode());
            LOG.warn(message);
            throw new HttpStatusException(method.getStatusCode(), method.getStatusText(), message);
        }
        if (resp == null) {
            String message = String.format("Unexpectedly empty response: %s.", resp);
            LOG.warn(message);
            throw new RuntimeException(message);
        }
        return parseResponse(resp);
    } catch (IOException e) {
        LOG.warn(String.format("Request failed: %s", e.getMessage()), e);
        throw Throwables.propagate(e);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
}

From source file:com.github.mjeanroy.springmvc.view.mustache.commons.IOUtils.java

/**
 * Close a {@link java.io.Closeable} object and do not throws a Checked Exception
 * if an exception occurs.//  ww  w  .  j  a v  a  2  s.  com
 *
 * @param stream Closeable stream.
 */
private static void closeQuietly(Closeable stream) {
    try {
        stream.close();
    } catch (IOException ex) {
        // Just log.
        log.debug(ex.getMessage(), ex);
    }
}