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:nl.dtls.fairdatapoint.api.controller.utils.HttpHeadersUtils.java

/**
 * Set response header for the internal server errors
 * // w ww .j  ava  2 s.  c  o  m
 * @param response  Http response
 * @param ex    Server exception
 * @return returns null (as a response body)
 */
public static String set500ResponseHeaders(HttpServletResponse response, Exception ex) {
    String errorMessage = ("Internal server error; Error message : " + ex.getMessage());
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    try {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMessage);
    } catch (IOException ex1) {
        LOGGER.warn(
                "Error setting error message for internal server " + "error; The error : " + ex1.getMessage());
    }
    response.setContentType(MediaType.TEXT_PLAIN_VALUE);
    return null;
}

From source file:se.vgregion.domain.infrastructure.webservice.RestCalendarEventsRepository.java

private static void closeClosables(Closeable... closables) {
    for (Closeable closeable : closables) {
        if (closeable != null) {
            try {
                closeable.close();//from  w  w w.  j a v a 2  s  . co m
            } catch (IOException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    }
}

From source file:applab.search.client.ImageManager.java

public static void getImages(List<String> imageIds) {
    if (imageIds != null) {
        for (String imageId : imageIds) {
            try {
                Log.d("Image Download", "Getting " + imageId);
                InputStream image = HttpHelpers
                        .getResource(Settings.getNewServerUrl() + "search/getsfimages?imageId=" + imageId);
                ImageFilesUtility.writeFile(imageId + ".jpg", image);
            } catch (IOException e) {
                Log.e("IOException", e.getMessage());
            }/*from  w w w .j  a  va  2  s. c  om*/
            JsonSimpleParser.incrementProgressLevel();
        }
    }
}

From source file:com.android.tools.idea.stats.UsageTrackerAnalyticsImpl.java

/**
 * Send a ping to Analytics on a separate thread
 *//*from  www.  ja v a 2 s.  c o  m*/
private static void sendPing(@NotNull final List<? extends NameValuePair> postData) {
    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override
        public void run() {
            CloseableHttpClient client = HttpClientBuilder.create().build();
            HttpPost request = new HttpPost(ANALYTICS_URL);
            try {
                request.setEntity(new UrlEncodedFormEntity(postData));
                HttpResponse response = client.execute(request);
                StatusLine status = response.getStatusLine();
                HttpEntity entity = response.getEntity(); // throw it away, don't care, not sure if we need to read in the response?
                if (status.getStatusCode() >= 300) {
                    LOG.debug("Non 200 status code : " + status.getStatusCode() + " - "
                            + status.getReasonPhrase());
                    // something went wrong, fail quietly, we probably have to diagnose analytics errors on our side
                    // usually analytics accepts ANY request and always returns 200
                }
            } catch (IOException e) {
                LOG.debug("IOException during Analytics Ping", e.getMessage());
                // something went wrong, fail quietly
            } finally {
                HttpClientUtils.closeQuietly(client);
            }
        }
    });
}

From source file:org.jboss.forge.shell.util.PluginUtil.java

public static void downloadFromURL(final PipeOut out, final URL url, final FileResource<?> resource)
        throws IOException {

    HttpGet httpGetManifest = new HttpGet(url.toExternalForm());
    out.print("Retrieving artifact ... ");

    HttpResponse response = new DefaultHttpClient().execute(httpGetManifest);
    switch (response.getStatusLine().getStatusCode()) {
    case 200://ww  w.j a va2 s. c  o m
        out.println("done.");
        try {
            resource.setContents(response.getEntity().getContent());
            out.println("done.");
        } catch (IOException e) {
            out.println("failed to download: " + e.getMessage());
        }

    default:
        out.println("failed! (server returned status code: " + response.getStatusLine().getStatusCode());
    }
}

From source file:com.microsoft.alm.plugin.idea.common.setup.WindowsStartup.java

/**
 * Run script to launch elevated process to create registry keys
 *
 * @param regeditFilePath/*from   w  w  w .  jav  a  2  s.  c o  m*/
 */
private static void launchElevatedCreation(final String regeditFilePath) {
    try {
        final String[] cmd = { "cmd", "/C", "regedit", "/s", regeditFilePath };
        final ProcessBuilder processBuilder = new ProcessBuilder(cmd);
        final Process process = processBuilder.start();
        process.waitFor();
    } catch (IOException e) {
        logger.warn("Running regedit encountered an IOException: {}", e.getMessage());
    } catch (Exception e) {
        logger.warn("Waiting for the process to execute resulted in an error: " + e.getMessage());
    }
}

From source file:org.linkedeconomy.espa.service.impl.rdf.SubProjectsImpl.java

public static void espaSubprojects() throws ParseException {

    //services for each table
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    SubProjectsService sub = (SubProjectsService) ctx.getBean("subProjectsServiceImpl");

    List<SubProjects> subProject = sub.getSubProjects();

    //--------------RDF Model--------------//
    Model model = ModelFactory.createDefaultModel();
    Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
    InfModel infModel = ModelFactory.createInfModel(reasoner, model);

    model.setNsPrefix("elod", OntologySpecification.elodPrefix);
    model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix);
    model.setNsPrefix("dcterms", OntologySpecification.dctermsPrefix);

    //number format
    DecimalFormat df = new DecimalFormat("0.00");

    for (SubProjects subProject1 : subProject) {

        Resource instanceCurrency = infModel.createResource("http://linkedeconomy.org/resource/Currency/EUR");
        Resource instanceBudgetUps = infModel.createResource(OntologySpecification.instancePrefix
                + "UnitPriceSpecification/BudgetItem/" + subProject1.getOps() + "/" + subProject1.getId());
        Resource instanceBudget = infModel.createResource(OntologySpecification.instancePrefix + "BudgetItem/"
                + subProject1.getOps() + "/" + subProject1.getId());
        Resource instanceSubProject = infModel.createResource(OntologySpecification.instancePrefix
                + "Subproject/" + subProject1.getOps() + "/" + subProject1.getId());
        Resource instanceProject = infModel
                .createResource(OntologySpecification.instancePrefix + "Subsidy/" + subProject1.getOps());
        DateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy");
        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        java.util.Date stDateStarts;
        java.util.Date stDateEnds;
        stDateStarts = dfDate.parse(subProject1.getStart());
        stDateEnds = dfDate.parse(subProject1.getFinish());
        String startDate = df2.format(stDateStarts);
        String endDate = df2.format(stDateEnds);
        infModel.add(instanceProject, RDF.type, OntologySpecification.projectResource);
        infModel.add(instanceBudgetUps, RDF.type, OntologySpecification.priceSpecificationResource);
        infModel.add(instanceBudget, RDF.type, OntologySpecification.budgetResource);
        infModel.add(instanceSubProject, RDF.type, OntologySpecification.subProjectResource);
        instanceProject.addProperty(OntologySpecification.hasRelatedProject, instanceSubProject);
        instanceSubProject.addProperty(OntologySpecification.hasRelatedBudgetItem, instanceBudget);
        instanceBudget.addProperty(OntologySpecification.price, instanceBudgetUps);
        instanceBudgetUps.addProperty(OntologySpecification.hasCurrencyValue,
                df.format(subProject1.getBudget()), XSDDatatype.XSDfloat);
        instanceBudgetUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true",
                XSDDatatype.XSDboolean);
        instanceBudgetUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency);
        instanceSubProject.addProperty(OntologySpecification.startDate, startDate, XSDDatatype.XSDdateTime);
        instanceSubProject.addProperty(OntologySpecification.endDate, endDate, XSDDatatype.XSDdateTime);
        instanceSubProject.addProperty(OntologySpecification.title, String.valueOf(subProject1.getTitle()),
                "el");
    }// www . j  av a 2s . co  m

    try {
        FileOutputStream fout = new FileOutputStream(
                "/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/subProjectEspa.rdf");
        model.write(fout);
    } catch (IOException e) {
        System.out.println("Exception caught" + e.getMessage());
    }
}

From source file:ru.mystamps.web.validation.jsr303.ImageFileValidator.java

private static byte[] readFourBytes(InputStream is) {
    // CheckStyle: ignore MagicNumber for next 1 line
    byte[] bytes = new byte[4];
    try {/*from w w  w.j a v  a2  s .  co m*/
        int read = is.read(bytes, 0, bytes.length);
        if (read != bytes.length) {
            return null;
        }

        return bytes;

    } catch (IOException e) {
        LOG.warn("Error during reading from file: {}", e.getMessage());
        return null;
    }
}

From source file:org.dataone.proto.trove.mn.http.client.DataHttpClientHandler.java

public static synchronized InputStream executeGet(HttpClient httpclient, HttpGet httpGet)
        throws ServiceFailure, NotFound, InvalidToken, NotAuthorized, IdentifierNotUnique, UnsupportedType,
        InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidCredentials, InvalidRequest,
        AuthenticationTimeout, UnsupportedMetadataType, HttpException {

    InputStream response = null;/*  ww  w.  ja  v  a  2 s .  c  o m*/
    try {

        HttpResponse httpResponse = httpclient.execute(httpGet);
        if (httpResponse.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) {

            HttpEntity resEntity = httpResponse.getEntity();
            if (resEntity != null) {
                response = resEntity.getContent();
            } else {
                throw new ServiceFailure("1002",
                        "response code OK, but Entity not returned?" + httpResponse.toString());
            }
        } else {
            HttpExceptionHandler.deserializeAndThrowException(httpResponse);
        }
    } catch (IOException ex) {
        throw new ServiceFailure("1002", ex.getMessage());
    }
    return response;
}

From source file:Main.java

/**
 * Load a raw string resource.//from   www.ja  v  a 2 s .  co m
 * @param context The current context.
 * @param resourceId The resource id.
 * @return The loaded string.
 */
private static String getStringFromRawResource(Context context, int resourceId) {
    String result = null;

    InputStream is = context.getResources().openRawResource(resourceId);
    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } catch (IOException e) {
            Log.w("ApplicationUtils",
                    String.format("Unable to load resource %s: %s", resourceId, e.getMessage()));
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                Log.w("ApplicationUtils",
                        String.format("Unable to load resource %s: %s", resourceId, e.getMessage()));
            }
        }
        result = sb.toString();
    } else {
        result = "";
    }

    return result;
}